{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "070a3f25-8ace-418b-8793-15144205f677",
   "metadata": {},
   "source": [
    "# Bedrock with LangChain using a Prompt that includes Context\n",
    "\n",
    "please refer the detail : https://github.com/aws-samples/amazon-bedrock-workshop/blob/main/01_Generation/02_contextual_generation.ipynb"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bd03b999-bd91-4928-ba3f-ce11cbc23b53",
   "metadata": {},
   "source": [
    "## install dependencies"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b095889e-d9d8-424a-a659-775f9b9df299",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: boto3 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (1.34.42)\n",
      "Requirement already satisfied: botocore<1.35.0,>=1.34.42 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from boto3) (1.34.42)\n",
      "Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from boto3) (1.0.1)\n",
      "Requirement already satisfied: s3transfer<0.11.0,>=0.10.0 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from boto3) (0.10.0)\n",
      "Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from botocore<1.35.0,>=1.34.42->boto3) (2.8.2)\n",
      "Requirement already satisfied: urllib3<2.1,>=1.25.4 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from botocore<1.35.0,>=1.34.42->boto3) (2.0.7)\n",
      "Requirement already satisfied: six>=1.5 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from python-dateutil<3.0.0,>=2.1->botocore<1.35.0,>=1.34.42->boto3) (1.16.0)\n",
      "Requirement already satisfied: langchain in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (0.1.7)\n",
      "Requirement already satisfied: PyYAML>=5.3 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from langchain) (6.0.1)\n",
      "Requirement already satisfied: SQLAlchemy<3,>=1.4 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from langchain) (2.0.27)\n",
      "Requirement already satisfied: aiohttp<4.0.0,>=3.8.3 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from langchain) (3.9.3)\n",
      "Requirement already satisfied: async-timeout<5.0.0,>=4.0.0 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from langchain) (4.0.3)\n",
      "Requirement already satisfied: dataclasses-json<0.7,>=0.5.7 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from langchain) (0.6.4)\n",
      "Requirement already satisfied: jsonpatch<2.0,>=1.33 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from langchain) (1.33)\n",
      "Requirement already satisfied: langchain-community<0.1,>=0.0.20 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from langchain) (0.0.20)\n",
      "Requirement already satisfied: langchain-core<0.2,>=0.1.22 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from langchain) (0.1.23)\n",
      "Requirement already satisfied: langsmith<0.1,>=0.0.83 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from langchain) (0.0.87)\n",
      "Requirement already satisfied: numpy<2,>=1 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from langchain) (1.26.1)\n",
      "Requirement already satisfied: pydantic<3,>=1 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from langchain) (2.4.2)\n",
      "Requirement already satisfied: requests<3,>=2 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from langchain) (2.31.0)\n",
      "Requirement already satisfied: tenacity<9.0.0,>=8.1.0 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from langchain) (8.2.3)\n",
      "Requirement already satisfied: aiosignal>=1.1.2 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.3.1)\n",
      "Requirement already satisfied: attrs>=17.3.0 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (23.1.0)\n",
      "Requirement already satisfied: frozenlist>=1.1.1 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.4.1)\n",
      "Requirement already satisfied: multidict<7.0,>=4.5 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (6.0.5)\n",
      "Requirement already satisfied: yarl<2.0,>=1.0 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.9.4)\n",
      "Requirement already satisfied: marshmallow<4.0.0,>=3.18.0 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from dataclasses-json<0.7,>=0.5.7->langchain) (3.20.2)\n",
      "Requirement already satisfied: typing-inspect<1,>=0.4.0 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from dataclasses-json<0.7,>=0.5.7->langchain) (0.9.0)\n",
      "Requirement already satisfied: jsonpointer>=1.9 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from jsonpatch<2.0,>=1.33->langchain) (2.4)\n",
      "Requirement already satisfied: anyio<5,>=3 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from langchain-core<0.2,>=0.1.22->langchain) (4.0.0)\n",
      "Requirement already satisfied: packaging<24.0,>=23.2 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from langchain-core<0.2,>=0.1.22->langchain) (23.2)\n",
      "Requirement already satisfied: annotated-types>=0.4.0 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from pydantic<3,>=1->langchain) (0.6.0)\n",
      "Requirement already satisfied: pydantic-core==2.10.1 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from pydantic<3,>=1->langchain) (2.10.1)\n",
      "Requirement already satisfied: typing-extensions>=4.6.1 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from pydantic<3,>=1->langchain) (4.8.0)\n",
      "Requirement already satisfied: charset-normalizer<4,>=2 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from requests<3,>=2->langchain) (3.3.1)\n",
      "Requirement already satisfied: idna<4,>=2.5 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from requests<3,>=2->langchain) (3.4)\n",
      "Requirement already satisfied: urllib3<3,>=1.21.1 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from requests<3,>=2->langchain) (2.0.7)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from requests<3,>=2->langchain) (2023.7.22)\n",
      "Requirement already satisfied: greenlet!=0.4.17 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from SQLAlchemy<3,>=1.4->langchain) (3.0.3)\n",
      "Requirement already satisfied: sniffio>=1.1 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from anyio<5,>=3->langchain-core<0.2,>=0.1.22->langchain) (1.3.0)\n",
      "Requirement already satisfied: exceptiongroup>=1.0.2 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from anyio<5,>=3->langchain-core<0.2,>=0.1.22->langchain) (1.1.3)\n",
      "Requirement already satisfied: mypy-extensions>=0.3.0 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from typing-inspect<1,>=0.4.0->dataclasses-json<0.7,>=0.5.7->langchain) (1.0.0)\n",
      "Requirement already satisfied: langchainhub in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (0.1.14)\n",
      "Requirement already satisfied: requests<3,>=2 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from langchainhub) (2.31.0)\n",
      "Requirement already satisfied: types-requests<3.0.0.0,>=2.31.0.2 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from langchainhub) (2.31.0.20240125)\n",
      "Requirement already satisfied: charset-normalizer<4,>=2 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from requests<3,>=2->langchainhub) (3.3.1)\n",
      "Requirement already satisfied: idna<4,>=2.5 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from requests<3,>=2->langchainhub) (3.4)\n",
      "Requirement already satisfied: urllib3<3,>=1.21.1 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from requests<3,>=2->langchainhub) (2.0.7)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in /home/ec2-user/anaconda3/envs/pytorch_p310/lib/python3.10/site-packages (from requests<3,>=2->langchainhub) (2023.7.22)\n"
     ]
    }
   ],
   "source": [
    "# dependencies\n",
    "!pip install --upgrade boto3\n",
    "!pip install langchain\n",
    "!pip install langchainhub"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6ace3e33-1e11-45f0-8ae7-50ff892723c5",
   "metadata": {},
   "source": [
    "## check bedrock availability"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b31cc8e5-6a23-4e36-a3ab-d396f272053e",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Create new client\n",
      "  Using region: None\n",
      "boto3 Bedrock client successfully created!\n",
      "bedrock-runtime(https://bedrock-runtime.us-east-1.amazonaws.com)\n"
     ]
    }
   ],
   "source": [
    "import json\n",
    "import os\n",
    "import sys\n",
    "\n",
    "import boto3\n",
    "import botocore\n",
    "\n",
    "module_path = \"..\"\n",
    "sys.path.append(os.path.abspath(module_path))\n",
    "from utils import bedrock, print_ww\n",
    "\n",
    "boto3_bedrock = bedrock.get_bedrock_client()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cbcca20f-f966-457b-a6ab-eb455937064f",
   "metadata": {
    "tags": []
   },
   "source": [
    "## build a God Role"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dda45070-e87e-4b1e-a016-fcb2c6fce77d",
   "metadata": {},
   "source": [
    "### God Template\n",
    "\n",
    "God is an absolute neutral role, responsilbe for game loop, and message delivery"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "82ed41d3-da3f-43f7-9f06-5b8e8f912aca",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from langchain.prompts import PromptTemplate\n",
    "\n",
    "template = \"\"\"你是一个社交游戏达人，熟知《狼人杀》游戏规则：\n",
    "{game_rule}\n",
    "\n",
    "现在你在扮演《狼人杀》游戏的上帝角色.\n",
    "\n",
    "你熟知上帝可以执行的操作:\n",
    "<commands>\n",
    "- 狼人确认？夜间和狼人确认投票对象\n",
    "- 全体确认？白天和所有玩家确认投票对象\n",
    "</commdands>\n",
    "\n",
    "目前游戏进程:\n",
    "<history>\n",
    "{history}\n",
    "</history>\n",
    "\n",
    "Human: {input}\n",
    "\n",
    "接下来你所有的回答必须同时满足下面所有要求:\n",
    "- 你的操作必须从<commands>选择, 每次只选择一个操作\n",
    "- 你不能泄露关键信息给玩家\n",
    "- 直接说出最终答案，控制输出字数为50字以内，消灭啰嗦\n",
    "- 面对无关话题，直接回答 \"无可奉告\"\n",
    "\n",
    "AI Assistant:\"\"\"\n",
    "\n",
    "God_template=template.replace(\"{game_rule}\", whoiswolf_rule_v1)\n",
    "\n",
    "God_prompt = PromptTemplate(input_variables=[\"history\", \"input\"], template=God_template)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6ae46c16-4628-4e8f-8b65-e07430e9d981",
   "metadata": {},
   "source": [
    "### use langchain to call bedrock api\n",
    "\n",
    "detail usage refer: https://python.langchain.com/docs/integrations/chat/bedrock"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "e37cce65-1172-41a0-995f-0d769f47a4a4",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/05/2024 05:57:45 AM Found credentials from IAM Role: BaseNotebookInstanceEc2InstanceRole\n"
     ]
    }
   ],
   "source": [
    "from langchain.chains import ConversationChain\n",
    "from langchain.memory import ConversationBufferMemory\n",
    "from langchain.memory import ConversationKGMemory\n",
    "from langchain.chains.conversation.memory import ConversationSummaryMemory\n",
    "from langchain.chains.conversation.memory import ConversationBufferWindowMemory\n",
    "\n",
    "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler\n",
    "from langchain_community.llms import Bedrock\n",
    "\n",
    "inference_modifier = {'max_tokens_to_sample':4096, \n",
    "                      \"temperature\":0.85,\n",
    "                      \"top_k\":250,\n",
    "                      \"top_p\":1,\n",
    "                      \"stop_sequences\": [\"\\n\\nHuman\"]\n",
    "                     }\n",
    "\n",
    "llm = Bedrock(\n",
    "    model_id=\"anthropic.claude-v2\",\n",
    "    streaming=True,\n",
    "    callbacks=[StreamingStdOutCallbackHandler()],\n",
    "    model_kwargs=inference_modifier,\n",
    ")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "723ddee6-fb7d-4b57-b53c-b13d3c0f8a08",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/05/2024 05:57:46 AM Found credentials from IAM Role: BaseNotebookInstanceEc2InstanceRole\n"
     ]
    }
   ],
   "source": [
    "inference_modifier = {'max_tokens_to_sample':4096, \n",
    "                      \"temperature\":0.85,\n",
    "                      \"top_k\":250,\n",
    "                      \"top_p\":1,\n",
    "                      \"stop_sequences\": [\"\\n\\nHuman\"]\n",
    "                     }\n",
    "\n",
    "def ClearGodMemory():\n",
    "    god_conversation.memory.clear()\n",
    "\n",
    "llm = Bedrock(\n",
    "    model_id=\"anthropic.claude-v2\",\n",
    "    streaming=True,\n",
    "    callbacks=[StreamingStdOutCallbackHandler()],\n",
    "    model_kwargs=inference_modifier,\n",
    ")\n",
    "\n",
    "god_conversation = ConversationChain(\n",
    "    prompt=God_prompt,\n",
    "    llm=llm, \n",
    "    verbose=False, \n",
    "    memory=ConversationBufferWindowMemory(k = 20, ai_prefix=\"AI Assistant\")\n",
    ")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "360e319d-3af4-4dfd-a0ee-0095486461e2",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "ClearGodMemory()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "db00bc5d-6dd3-48a2-ade8-5fb7c372ecc9",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "======template==========\n",
      "你是一个社交游戏达人，熟知《狼人杀》游戏规则：\n",
      "\n",
      "1. 游戏分狼人和村民两大阵营,他们的目标为:\n",
      "- 狼人团队 消灭所有村民。\n",
      "- 村民团队 消灭所有狼人,或游戏结束时存活一名村民。\n",
      "\n",
      "2. 游戏分白天和晚上两个阶段交替进行:\n",
      "- 晚上狼人睁眼互投票杀死一名玩家, 村名不能睁眼\n",
      "- 白天所有存活玩家需要公开讨论，最后一起投票决定消灭一名疑似狼人的角色, 玩家也可以放弃投票\n",
      "\n",
      "\n",
      "现在你在扮演《狼人杀》游戏的上帝角色.\n",
      "\n",
      "你熟知上帝可以执行的操作:\n",
      "<commands>\n",
      "- 狼人确认？夜间和狼人确认投票对象\n",
      "- 全体确认？白天和所有玩家确认投票对象\n",
      "</commdands>\n",
      "\n",
      "目前游戏进程:\n",
      "<history>\n",
      "{history}\n",
      "</history>\n",
      "\n",
      "Human: {input}\n",
      "\n",
      "接下来你所有的回答必须同时满足下面所有要求:\n",
      "- 你的操作必须从<commands>选择, 每次只选择一个操作\n",
      "- 你不能泄露关键信息给玩家\n",
      "- 直接说出最终答案，控制输出字数为50字以内，消灭啰嗦\n",
      "- 面对无关话题，直接回答 \"无可奉告\"\n",
      "\n",
      "AI Assistant:\n",
      "======memory.buffer==========\n",
      "\n",
      "======memory==========\n",
      "ai_prefix='AI Assistant' k=20\n"
     ]
    }
   ],
   "source": [
    "print(\"======template==========\")\n",
    "print(god_conversation.prompt.template)\n",
    "print(\"======memory.buffer==========\")\n",
    "print(god_conversation.memory.buffer)\n",
    "print(\"======memory==========\")\n",
    "print(god_conversation.memory)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "b034f16d-ba3b-4d46-bce3-105986a15a04",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 狼人杀是一款多人参与的社交推理游戏。游戏分为狼人阵营和村民阵营。\n",
      "\n",
      "夜晚时,狼人睁眼互相认出队友,并投票决定杀死一名村民。白天时,全体玩家讨论并投票决定处死一名疑似狼人的玩家。 \n",
      "\n",
      "村民的目的是消灭所有狼人或最后存活一名村民。狼人的目的是消灭所有村民。游戏通过白天村民的讨论投票和夜晚狼人的暗杀来进行。"
     ]
    },
    {
     "data": {
      "text/plain": [
       "' 狼人杀是一款多人参与的社交推理游戏。游戏分为狼人阵营和村民阵营。\\n\\n夜晚时,狼人睁眼互相认出队友,并投票决定杀死一名村民。白天时,全体玩家讨论并投票决定处死一名疑似狼人的玩家。 \\n\\n村民的目的是消灭所有狼人或最后存活一名村民。狼人的目的是消灭所有村民。游戏通过白天村民的讨论投票和夜晚狼人的暗杀来进行。'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "god_conversation.predict(input=\"狼人杀是什么游戏规则？\")\n",
    "#conversation.predict(input=\"前面描述是什么游戏？规则如何\")\n",
    "# conversation.predict(input=\"女巫和猎人有什么技能？\")\n",
    "#conversation.predict(input=\"这个游戏建议几人游玩呢？\")\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "e338906b-66ff-4f48-8875-7e383c41472b",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 天黑请闭眼。\n",
      "\n",
      "晚上,狼人团队互相确认了目标。\n",
      "\n",
      "天亮了。\n",
      "\n",
      "全体确认?白天大家讨论后,决定消灭魏征。\n",
      "\n",
      "天黑请闭眼。 \n",
      "\n",
      "晚上,狼人团队互相确认了目标。\n",
      "\n",
      "天亮了。\n",
      "\n",
      "全体确认?白天大家讨论后,决定消灭狼人之一的李白。\n",
      "\n",
      "村民获胜。无可奉告。"
     ]
    },
    {
     "data": {
      "text/plain": [
       "' 天黑请闭眼。\\n\\n晚上,狼人团队互相确认了目标。\\n\\n天亮了。\\n\\n全体确认?白天大家讨论后,决定消灭魏征。\\n\\n天黑请闭眼。 \\n\\n晚上,狼人团队互相确认了目标。\\n\\n天亮了。\\n\\n全体确认?白天大家讨论后,决定消灭狼人之一的李白。\\n\\n村民获胜。无可奉告。'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "god_conversation.predict(input=\"请给我设计6个玩家的姓名，最好使用中国的历史名人\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 338,
   "id": "b918ec57-a0ee-40f9-8e49-e14f70c9ee7e",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\n",
      "  \"players\": [\n",
      "    {\n",
      "      \"name\": \"林冲\",\n",
      "      \"role\": \"村民\",\n",
      "      \"character\": \"豪爽果断\",\n",
      "      \"status\": 1\n",
      "    },\n",
      "    {\n",
      "      \"name\": \"宋江\",\n",
      "      \"role\": \"狼人\", \n",
      "      \"character\": \"权谋多计\",\n",
      "      \"status\": 1\n",
      "    },\n",
      "    {\n",
      "      \"name\": \"吴用\",\n",
      "      \"role\": \"村民\",\n",
      "      \"character\": \"老实朴素\",\n",
      "      \"status\": 1\n",
      "    },\n",
      "    {\n",
      "      \"name\": \"卢俊义\",\n",
      "      \"role\": \"狼人\",\n",
      "      \"character\": \"精明能干\",\n",
      "      \"status\": 1\n",
      "    },\n",
      "    {\n",
      "      \"name\": \"武松\",\n",
      "      \"role\": \"村民\",\n",
      "      \"character\": \"鲁莽暴躁\",\n",
      "      \"status\": 1\n",
      "    },\n",
      "    {\n",
      "      \"name\": \"鲁智深\",\n",
      "      \"role\": \"村民\",\n",
      "      \"character\": \"沉稳睿智\", \n",
      "      \"status\": 1\n",
      "    }\n",
      "  ]\n",
      "}"
     ]
    },
    {
     "data": {
      "text/plain": [
       "' {\\n  \"players\": [\\n    {\\n      \"name\": \"林冲\",\\n      \"role\": \"村民\",\\n      \"character\": \"豪爽果断\",\\n      \"status\": 1\\n    },\\n    {\\n      \"name\": \"宋江\",\\n      \"role\": \"狼人\", \\n      \"character\": \"权谋多计\",\\n      \"status\": 1\\n    },\\n    {\\n      \"name\": \"吴用\",\\n      \"role\": \"村民\",\\n      \"character\": \"老实朴素\",\\n      \"status\": 1\\n    },\\n    {\\n      \"name\": \"卢俊义\",\\n      \"role\": \"狼人\",\\n      \"character\": \"精明能干\",\\n      \"status\": 1\\n    },\\n    {\\n      \"name\": \"武松\",\\n      \"role\": \"村民\",\\n      \"character\": \"鲁莽暴躁\",\\n      \"status\": 1\\n    },\\n    {\\n      \"name\": \"鲁智深\",\\n      \"role\": \"村民\",\\n      \"character\": \"沉稳睿智\", \\n      \"status\": 1\\n    }\\n  ]\\n}'"
      ]
     },
     "execution_count": 338,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gen_role_template = \"\"\"\n",
    "给每个玩家生成一段文字，包含自己的角色描述和游戏规则. 要求包含名字，游戏内身份，性格这三个信息，最后整理成json格式，\n",
    "包含的key有name, role, character, status。\n",
    "其中status只有0，1两个值，默认为1\n",
    "\"\"\"\n",
    "\n",
    "conversation.predict(input=gen_role_template)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "47b4681e-7405-4982-bab8-4c85bb02b184",
   "metadata": {},
   "source": [
    "### setup logging configuration & critial parseJson function"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 330,
   "id": "97445fef-e9d2-4419-9699-b917aedcd442",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import re\n",
    "import json\n",
    "import logging\n",
    "\n",
    "logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', level=logging.INFO)\n",
    "\n",
    "def Info(text):\n",
    "    logging.info(text)\n",
    "    \n",
    "def Debug(text):\n",
    "    logging.debug(text)\n",
    "\n",
    "def Warn(text):\n",
    "    logging.warning(text)\n",
    "\n",
    "def Error(text):\n",
    "    logging.error(text)\n",
    "    \n",
    "def Print(text):\n",
    "    print(text)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3c8c1fc4-b4ac-481f-baed-7147395ba91e",
   "metadata": {},
   "source": [
    "### define agent tools\n",
    "\n",
    "not really used in this project...."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 331,
   "id": "c3106943-8dd1-43bb-9da2-5a3bcf96e8b0",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from langchain.pydantic_v1 import BaseModel, Field\n",
    "from langchain.tools import BaseTool, StructuredTool, tool\n",
    "\n",
    "class GetAllPlayersName(BaseTool):\n",
    "    name = \"GetAllPlayersName\"\n",
    "    description = \"GetAllPlayersName\"\n",
    "\n",
    "    def _run(self, name: str):\n",
    "        players_name = []\n",
    "        for player in roles_dict[\"players\"]:\n",
    "            players_name.append(player[\"name\"]+\":\"+str(player[\"status\"]))\n",
    "        return \",\".join(players_name) \n",
    "\n",
    "    def _arun(self, radius: int):\n",
    "        raise NotImplementedError(\"This tool does not support async\")\n",
    "        \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5d13014c-4ad0-4167-a27c-3dc361dfcb0a",
   "metadata": {},
   "source": [
    "## build up Players based on PE"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9594e803-2d98-4391-ab31-08c6bc3affea",
   "metadata": {},
   "source": [
    "#### setup claude llm as driver"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 332,
   "id": "03dea169-61c2-474d-bbc4-baf619a9b12c",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 03:34:06 PM Found credentials from IAM Role: BaseNotebookInstanceEc2InstanceRole\n"
     ]
    }
   ],
   "source": [
    "from langchain.chains import ConversationChain\n",
    "from langchain.memory import ConversationBufferMemory\n",
    "from langchain.memory import ConversationKGMemory\n",
    "from langchain.chains.conversation.memory import ConversationSummaryMemory\n",
    "from langchain.chains.conversation.memory import ConversationBufferWindowMemory\n",
    "\n",
    "from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler\n",
    "from langchain_community.llms import Bedrock\n",
    "\n",
    "inference_modifier = {'max_tokens_to_sample':4096, \n",
    "                      \"temperature\":0.85,\n",
    "                      \"top_k\":250,\n",
    "                      \"top_p\":1,\n",
    "                      \"stop_sequences\": [\"\\n\\nHuman\"]\n",
    "                     }\n",
    "\n",
    "claude_llm = Bedrock(\n",
    "    model_id=\"anthropic.claude-v2\",\n",
    "    streaming=True,\n",
    "    callbacks=[StreamingStdOutCallbackHandler()],\n",
    "    model_kwargs=inference_modifier,\n",
    ")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "046dbfd0-037c-47e8-80b5-63e13b8b64ba",
   "metadata": {},
   "source": [
    "### Pin A Rule"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 358,
   "id": "e87d6d5f-4cad-4f15-970f-419cf06240f4",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "whoiswolf_rule_v1 = \"\"\"\n",
    "1. 游戏分狼人和村民两大阵营,他们的目标为:\n",
    "- 狼人团队 消灭所有村民。\n",
    "- 村民团队 消灭所有狼人,或游戏结束时存活一名村民。\n",
    "\n",
    "2. 游戏分白天和晚上两个阶段交替进行:\n",
    "- 晚上狼人睁眼互投票杀死一名玩家, 村名不能睁眼\n",
    "- 白天所有存活玩家需要公开讨论，最后一起投票决定消灭一名疑似狼人的角色, 玩家也可以放弃投票\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a74279d2-5066-4283-9113-3707583970aa",
   "metadata": {},
   "source": [
    "### God Class"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 359,
   "id": "0124902e-1459-4efd-a1a0-873e0f190a04",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "class GodAgent:\n",
    "    def __init__(self):\n",
    "        pass"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9f5f2191-062c-4a9f-86a4-bb288cfd5afe",
   "metadata": {},
   "source": [
    "### Player Class"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 360,
   "id": "ff547a8d-4326-4d07-81c2-76672809cbb8",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from langchain.prompts import PromptTemplate\n",
    "\n",
    "def ActionLog(prefix, current_time, agent, res_obj):\n",
    "    action_log = {\"time\": current_time, \"player\": agent[\"name\"], \"status\": agent['status'], \"response\": res_obj}\n",
    "    Debug(\"\\n {0}={1}\\n\".format(prefix, action_log))\n",
    "    return action_log\n",
    "\n",
    "def ReadableActionLog(prefix, current_time, agent, res_obj):\n",
    "    action_log = \"[玩家{0}于时间{1}, 执行动作为:{2}]\".format(agent[\"name\"],current_time, res_obj)\n",
    "    return action_log\n",
    "\n",
    "def SystemLog(prefix, current_time, agent, res_obj):\n",
    "    action_log = {\"time\": current_time, \"player\": agent[\"name\"], \"status\": agent['status'], \n",
    "                      \"role\": agent[\"role\"], \"character\": agent[\"character\"], \"response\": res_obj}\n",
    "    Info(\"\\n {0}={1}\\n\".format(prefix, action_log))\n",
    "    return action_log\n",
    "    \n",
    "class PlayerAgent:\n",
    "    def __init__(self, player):\n",
    "        confirmed_role = template_role.replace(\"{nickname}\", player[\"name\"])\n",
    "        confirmed_role = confirmed_role.replace(\"{role}\", player[\"role\"])\n",
    "        confirmed_role = confirmed_role.replace(\"{character}\", player[\"character\"])\n",
    "        confirmed_role = confirmed_role.replace(\"{init_players}\", GetAllPlayersName())\n",
    "\n",
    "        if player[\"role\"] == \"狼人\":\n",
    "            confirmed_role = confirmed_role.replace(\"{teammates}\", GetAllWolvesName())\n",
    "        if player[\"role\"] == \"村民\":\n",
    "            confirmed_role = confirmed_role.replace(\"{teammates}\", game_config_dict[\"player\"][\"action_villager_team\"])\n",
    "\n",
    "        prompt_role = PromptTemplate.from_template(confirmed_role)\n",
    "        prompt_role.format(chat_history=\"\", input=\"\")\n",
    "\n",
    "        role_memory = ConversationBufferWindowMemory(k = 20, ai_prefix=\"AI Assistant\", memory_key=\"chat_history\", input_key=\"input\")\n",
    "        \n",
    "        # Construct the ReAct agent\n",
    "        # initialize agent with tools\n",
    "        # player[\"conversation\"] = initialize_agent(\n",
    "        #     agent=AgentType.CONVERSATIONAL_REACT_DESCRIPTION,\n",
    "        #     tools=tools,\n",
    "        #     llm=claude_llm,\n",
    "        #     verbose=False,\n",
    "        #     max_iterations=3,\n",
    "        #     early_stopping_method='generate',\n",
    "        #     memory=role_memory\n",
    "        # )\n",
    "        #agent = create_react_agent(claude_llm, tools, prompt_role)\n",
    "        #player[\"agent_executor\"] = AgentExecutor(agent=agent, tools=tools, verbose=False, memory=memory)\n",
    "\n",
    "        player[\"conversation\"] = ConversationChain(\n",
    "            prompt=prompt_role,\n",
    "            llm=claude_llm, \n",
    "            verbose=False, \n",
    "            memory=role_memory\n",
    "        )\n",
    "        \n",
    "        self.agent = player  \n",
    "        Debug(self.agent[\"conversation\"])\n",
    "        pass\n",
    "    \n",
    "    def PlayerInvoke(self, question):\n",
    "        Info(\"\\tQUESTION: \" + question)\n",
    "        return self.agent[\"conversation\"].invoke(input = question)\n",
    "    \n",
    "    def PlayerAddMemory(self, inputInfo):\n",
    "        outputInfo = game_config_dict[\"player\"][\"action_confirm\"]\n",
    "        self.agent[\"conversation\"].memory.save_context({\"input\": inputInfo}, {\"ouput\": outputInfo})\n",
    "        pass\n",
    "        \n",
    "    def PlayerAction(self, i, isDay, current_time, message, voteFlag=False):\n",
    "        log = {}\n",
    "        response = []\n",
    "        output = \"\"\n",
    "        context = \"\"\n",
    "        # 如果玩家是死亡状态\n",
    "        if self.agent['status'] == -1:\n",
    "            pass\n",
    "        # 如果玩家是遗言状态\n",
    "        if self.agent['status'] == 0:\n",
    "            self.DeathWords(i, isDay, current_time)\n",
    "            pass\n",
    "        # 如果玩家是存活状态\n",
    "        if self.agent['status'] == 1: \n",
    "            if isDay:\n",
    "                context = self.PlayerReflect(message, current_time)\n",
    "                \n",
    "                # Info(\"\\t CONTEXT: \"+context)\n",
    "                if voteFlag:\n",
    "                    question = game_config_dict[\"player\"][\"action_plan_day_vote\"].format(context, \"\", i)\n",
    "                else:\n",
    "                    question = game_config_dict[\"player\"][\"action_plan_day\"].format(context, \"\", i)\n",
    "                output = self.PlayerInvoke(question)\n",
    "            else:\n",
    "                question = game_config_dict[\"player\"][\"action_plan_night\"].format(\"\", \"\", i)\n",
    "                output = self.PlayerInvoke(question)\n",
    "        \n",
    "        # parse LLM output\n",
    "        if output != \"\":\n",
    "            response = ParseJson(output[\"response\"])\n",
    "            for res in response:\n",
    "                res_obj = json.loads(res)\n",
    "\n",
    "                if res_obj[\"action\"] == \"WolfVote\":\n",
    "                    log = ActionLog(\"wolf_vote_log\", current_time, self.agent, res_obj)\n",
    "                    wolf_action_log_dict.append(log)\n",
    "\n",
    "                if res_obj[\"action\"] == \"PlayerVote\":\n",
    "                    log = ActionLog(\"player_vote_log\", current_time, self.agent, res_obj)\n",
    "                    player_action_log_dict.append(log)\n",
    "                    log = ReadableActionLog(\"player_vote_log\", current_time, self.agent, res_obj)\n",
    "                    game_public_log_dict.append(log)\n",
    "\n",
    "                if res_obj[\"action\"] == \"Debate\":\n",
    "                    log = ActionLog(\"player_debate_log\", current_time, self.agent, res_obj)\n",
    "                    player_action_log_dict.append(log)\n",
    "                    log = ReadableActionLog(\"player_debate_log\", current_time, self.agent, res_obj)\n",
    "                    game_public_log_dict.append(log)\n",
    "                    pass\n",
    "                    \n",
    "                if res_obj[\"action\"] == \"GetAllPlayersName\":\n",
    "                    log = ActionLog(\"player_check_log\", current_time, self.agent, res_obj)\n",
    "                    # Add Extra memory\n",
    "                    inputInfo = game_config_dict[\"system\"][\"board\"].format(GetAllPlayersName())\n",
    "                    Info(\"\\t GetAllPlayersName: \" + inputInfo)\n",
    "                    self.PlayerAddMemory(inputInfo)\n",
    "\n",
    "            game_system_log_dict.append(SystemLog(\"[ROUND ACTION]\", current_time, self.agent, response))\n",
    "            pass\n",
    "        \n",
    "    def PlayerReflect(self, message, current_time): \n",
    "        PlayersAllActions = []\n",
    "        for action in game_public_log_dict:\n",
    "            #if action[\"time\"] == current_time:\n",
    "            PlayersAllActions.append(json.dumps(action, ensure_ascii=False))\n",
    "                \n",
    "        context = \"\"\n",
    "        if len(PlayersAllActions) > 0:\n",
    "            context = \"日志为:\"+\" \".join(PlayersAllActions) + \".根据日志,先进行形式分析\"\n",
    "            \n",
    "        question = game_config_dict[\"player\"][\"action_reflect\"].format(message, context)\n",
    "        output = self.PlayerInvoke(question)\n",
    "        # parse LLM output\n",
    "        if output != \"\":\n",
    "            Debug(\"\\tREFLECT: \" + output[\"response\"])\n",
    "            return output[\"response\"]\n",
    "        return \"\"\n",
    "\n",
    "    def DeathWords(self, i, isDay, current_time):\n",
    "        # 如果玩家是死亡状态\n",
    "        Debug(\"player: {0} status: {1}\".format(self.agent['name'], self.agent['status']))\n",
    "        if self.agent['status'] == 0:\n",
    "            self.agent['status'] = -1 ### never talk\n",
    "            \n",
    "            question = game_config_dict[\"player\"][\"action_plan_death\"].format(i)\n",
    "            output = self.PlayerInvoke(question)\n",
    "            response = ParseJson(output[\"response\"])\n",
    "            for res in response:\n",
    "                res_obj = json.loads(res)\n",
    "                if res_obj[\"action\"] == \"DeathWords\":\n",
    "                    log = ReadableActionLog(\"player_debate_log\", current_time, self.agent, res_obj)\n",
    "                    game_public_log_dict.append(log)\n",
    "                    # detah words!!!!\n",
    "                    if isDay:\n",
    "                        return game_config_dict[\"system\"][\"death_day\"].format(self.agent[\"name\"], res_obj[\"content\"])\n",
    "                    else:\n",
    "                        return game_config_dict[\"system\"][\"death_night\"].format(self.agent[\"name\"], res_obj[\"content\"])\n",
    "        \n",
    "        return None"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e6b57688-edb2-4a0d-a2cb-64450ab80b3a",
   "metadata": {},
   "source": [
    "### global variables"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 379,
   "id": "6965124f-8271-4392-b200-91c8801094ed",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:03:14 PM {'players': [{'name': 'P1', 'role': '狼人', 'character': '思维缜密', 'status': 0}, {'name': 'P2', 'role': '狼人', 'character': '沉默寡言', 'status': 0}, {'name': 'P3', 'role': '村民', 'character': '能说会道', 'status': 1}, {'name': 'P4', 'role': '村民', 'character': '逻辑清晰', 'status': 1}, {'name': 'P5', 'role': '村民', 'character': '思维跳跃', 'status': 1}, {'name': 'P6', 'role': '村民', 'character': '心不在焉', 'status': 1}, {'name': 'P7', 'role': '村民', 'character': '喜欢附和', 'status': 1}]}\n",
      "02/15/2024 04:03:14 PM 狼人:0 村民:5\n",
      "02/15/2024 04:03:14 PM 1\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[]\n"
     ]
    }
   ],
   "source": [
    "import json\n",
    "# import a groupby() method\n",
    "# from itertools module\n",
    "from itertools import groupby\n",
    "\n",
    "roles = \"\"\"\n",
    "{\n",
    "  \"players\": [\n",
    "    {\n",
    "      \"name\": \"P1\",\n",
    "      \"role\": \"狼人\",\n",
    "      \"character\": \"思维缜密\",\n",
    "      \"status\": 0\n",
    "    },\n",
    "    {\n",
    "      \"name\": \"P2\",\n",
    "      \"role\": \"狼人\", \n",
    "      \"character\": \"沉默寡言\",\n",
    "      \"status\": 0\n",
    "    },\n",
    "    {\n",
    "      \"name\": \"P3\",\n",
    "      \"role\": \"村民\",\n",
    "      \"character\": \"能说会道\",\n",
    "      \"status\": 1\n",
    "    },\n",
    "    {\n",
    "      \"name\": \"P4\",\n",
    "      \"role\": \"村民\",\n",
    "      \"character\": \"逻辑清晰\",\n",
    "      \"status\": 1\n",
    "    },\n",
    "    {\n",
    "      \"name\": \"P5\",\n",
    "      \"role\": \"村民\",\n",
    "      \"character\": \"思维跳跃\",\n",
    "      \"status\": 1\n",
    "    },\n",
    "    {\n",
    "      \"name\": \"P6\",\n",
    "      \"role\": \"村民\",\n",
    "      \"character\": \"心不在焉\", \n",
    "      \"status\": 1\n",
    "    },\n",
    "    {\n",
    "      \"name\": \"P7\",\n",
    "      \"role\": \"村民\",\n",
    "      \"character\": \"喜欢附和\", \n",
    "      \"status\": 1\n",
    "    }\n",
    "  ]\n",
    "}\n",
    "\"\"\"\n",
    "\n",
    "def ReloadRoles():\n",
    "    return json.loads(roles)\n",
    "\n",
    "def ReviveRoles():\n",
    "    for player in roles_dict[\"players\"]:\n",
    "        player[\"status\"] = 1\n",
    "        \n",
    "# @tool\n",
    "def GetAllPlayersName() -> str:\n",
    "    \"\"\"GetAllPlayersName\"\"\"\n",
    "    players_name = []\n",
    "    for player in roles_dict[\"players\"]:\n",
    "        players_name.append(player[\"name\"]+\":\"+str(player[\"status\"]))\n",
    "    return \",\".join(players_name)  \n",
    "\n",
    "    \n",
    "# @tool\n",
    "def GetAllWolvesName() -> str:\n",
    "    \"\"\"GetAllWolvesName\"\"\"\n",
    "    wolves_name = []\n",
    "    for player in roles_dict[\"players\"]:\n",
    "        if player[\"role\"] == \"狼人\":\n",
    "            wolves_name.append(player[\"name\"])\n",
    "    return \",\".join(wolves_name) \n",
    "\n",
    "def CheckWinner() -> int:\n",
    "    \"\"\"CheckWinner\"\"\"\n",
    "    # Using a loop\n",
    "    # Grouping dictionary keys by value\n",
    "    grouped_dict = {\"狼人\":[], \"村民\":[]}\n",
    "    for player in roles_dict[\"players\"]:\n",
    "        if player[\"status\"] == 1:\n",
    "            if player[\"role\"] not in grouped_dict:\n",
    "                grouped_dict[player[\"role\"]] = []\n",
    "            grouped_dict[player[\"role\"]].append(player)\n",
    "            \n",
    "    print(grouped_dict[\"狼人\"])\n",
    "    Info(\"狼人:{0} 村民:{1}\".format(str(len(grouped_dict[\"狼人\"])), str(len(grouped_dict[\"村民\"]))))\n",
    "\n",
    "    if len(grouped_dict[\"狼人\"]) == 0 and len(grouped_dict[\"村民\"]) > 0:\n",
    "        return 1\n",
    "    if len(grouped_dict[\"狼人\"]) > 0 and len(grouped_dict[\"村民\"]) == 0:\n",
    "        return 2  \n",
    "    return 0\n",
    "    \n",
    "roles_dict = ReloadRoles()\n",
    "Info(roles_dict)\n",
    "Info(CheckWinner())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 380,
   "id": "cc2fd8d9-b0b4-4a0f-a65d-6061b9ad2f62",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:03:15 PM P1:0,P2:0,P3:1,P4:1,P5:1,P6:1,P7:1\n",
      "02/15/2024 04:03:15 PM P1,P2\n",
      "02/15/2024 04:03:15 PM ['{\"name\": \"John\"}', '{\"age\": 30}', '{\"gender\": \"male\"}', '{\"name\": \"John\"}', '{\"age\": 30}', '{\"gender\": \"male\"}']\n"
     ]
    }
   ],
   "source": [
    "import json\n",
    "import queue\n",
    "\n",
    "game_config = \"\"\"\n",
    "{\n",
    "    \"max_round\": 1,\n",
    "    \"player\": {\n",
    "        \"action_plan_night\": \"{0} {1} 现在是第{2}天夜晚，该如何行动?\",\n",
    "        \"action_plan_day\": \"{0} {1} 现在是第{2}天白天的讨论环节，该如何行动?\",\n",
    "        \"action_plan_day_vote\": \"{0} {1} 现在是第{2}天白天的投票环节，该如何行动?\",\n",
    "        \"action_plan_death\": \"现在是第{0}天白天，玩家已经死亡,有何遗言?\",\n",
    "        \"action_confirm\": \"收到\",\n",
    "        \"action_villager_team\": \"未知,需要你推理发现.\",\n",
    "        \"action_reflect\": \"{0} {1} 该如何思考?\",\n",
    "        \"action_plan_test\": \"现在全场几人活着几人淘汰\"\n",
    "    },\n",
    "    \"god\": {\n",
    "        \"action_plan_night\": \"{0}现在是第{1}天夜晚，你该如何行动？\",\n",
    "        \"action_plan_day\": \"{0}现在是第{1}天白天，你该如何行动？\",\n",
    "        \"action_plan_test\": \"现在全场几人活着几人淘汰\"\n",
    "    },\n",
    "    \"system\": {\n",
    "        \"death_night\": \"昨晚, 玩家{0}被狼人淘汰, 遗言为:{1}.\",\n",
    "        \"death_day\": \"今天, 玩家{0}被玩家淘汰, 遗言为:{1}.\",\n",
    "        \"win_wolf\": \"狼人胜利!\",\n",
    "        \"win_villager\": \"村民胜利!\",\n",
    "        \"win_none\": \"游戏继续. 目前玩家存活情况:{0}\",\n",
    "        \"board\": \"现在玩家存活情况:{0}\"\n",
    "    }\n",
    "}\n",
    "\"\"\"\n",
    "game_config_dict = json.loads(game_config)\n",
    "game_system_log_dict = []\n",
    "game_public_log_dict = []\n",
    "wolf_action_log_dict = []\n",
    "player_action_log_dict = []\n",
    "\n",
    "## clear Players Memory  \n",
    "def ClearPlayersMemory():\n",
    "    for player in roles_dict[\"players\"]:\n",
    "        player[\"conversation\"].memory.clear()\n",
    "\n",
    "def ResetGlobal():\n",
    "    Info(\"===== ResetGlobal =====\")\n",
    "    global game_config_dict, game_system_log_dict, game_public_log_dict, wolf_action_log_dict, player_action_log_dict\n",
    "    game_config_dict = json.loads(game_config)\n",
    "    game_system_log_dict = []\n",
    "    game_public_log_dict = []\n",
    "    wolf_action_log_dict = []\n",
    "    player_action_log_dict = []\n",
    " \n",
    "\n",
    "Info(GetAllPlayersName())\n",
    "Info(GetAllWolvesName())\n",
    "tools = [GetAllPlayersName()]\n",
    "def ParseJson(text):\n",
    "    # 使用正则表达式查找 {} 之间的内容\n",
    "    json_pattern = re.compile( r'{[\\s\\S]*?}') \n",
    "    json_strings = re.findall(json_pattern, text)\n",
    "    return json_strings\n",
    "\n",
    "Info(ParseJson(\"\"\"\n",
    "大家好呀\n",
    "{\"name\": \"John\"}\n",
    "{\"age\": 30}\n",
    "{\"gender\": \"male\"}\n",
    "大家好呀\n",
    "{\"name\": \"John\"}\n",
    "{\"age\": 30}\n",
    "{\"gender\": \"male\"}\n",
    "\n",
    "\"\"\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "207e55a6-18c8-4d9c-88ce-7f8a1ea84fa0",
   "metadata": {},
   "source": [
    "### player pe template"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 381,
   "id": "2f4f4055-7420-4273-baad-8a63ff5b1c13",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "whoiswolf_rule_v1 = \"\"\"\n",
    "1. 游戏分狼人和村民两大阵营,他们的目标为:\n",
    "- 狼人团队 消灭所有村民。\n",
    "- 村民团队 消灭所有狼人,或游戏结束时存活一名村民。\n",
    "\n",
    "2. 游戏分白天和晚上两个阶段交替进行:\n",
    "- 晚上狼人睁眼互投票杀死一名玩家, 村名不能睁眼\n",
    "- 白天所有存活玩家需要公开讨论, 最后一起投票决定消灭一名疑似狼人的角色, 玩家也可以放弃投票\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 382,
   "id": "5edf060b-d5ed-48c6-b1f1-4eca7176663b",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "\n",
    "whoiswolf_command_v1 = \"\"\"\n",
    "- 获取玩家信息: GetAllPlayersName 参数: 无\n",
    "- 狼人夜晚投票: WolfVote 参数: target=目标玩家(任意活着的玩家)\n",
    "- 玩家白天投票: PlayerVote 参数: target=目标玩家(任意活着的玩家)\n",
    "- 放弃行动: Pass 参数: 无\n",
    "- 白天玩家讨论: Debate 参数: content=理由\n",
    "- 玩家死亡: DeathWords 参数: content=遗言，给予存活玩家线索\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 386,
   "id": "260cc69c-4bb3-4aa5-8b80-e9d25f35143b",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "\n",
    "template_role = \"\"\"你是资深的社交游戏助手, 熟悉《狼人杀》游戏规则:\n",
    "<game_rules>\n",
    "{game_rule}\n",
    "</game_rules>\n",
    "\n",
    "你熟悉该游戏熟悉所有命令:\n",
    "<commands>\n",
    "{commands}\n",
    "</commands>\n",
    "\n",
    "<references>\n",
    "- {{\"action\": \"Pass\"}}\n",
    "- {{\"action\": \"GetAllPlayersName\"}}\n",
    "- {{\"action\": \"WolfVote\", \"target\": \"小明\"}}\n",
    "- {{\"action\": \"PlayerVote\", \"target\": \"老王\"}}\n",
    "- {{\"action\": \"Debate\", \"content\": \"我的身份是普通村民，大家不要投我\"}}\n",
    "- {{\"action\": \"Debate\", \"content\": \"我摊牌了，我就是狼\"}}\n",
    "- {{\"action\": \"DeathWords\", \"content\": \"我觉得2号有很大的嫌疑\"}}\n",
    "- {{\"action\": \"DeathWords\", \"content\": \"我没有遗言\"}}\n",
    "</references>\n",
    "\n",
    "<reflections>\n",
    "- 我认为...\n",
    "- 我是这么想的...\n",
    "</reflections>\n",
    "\n",
    "现在玩家是 {nickname}, 身份是 {role}, 性格为 {character}, \n",
    "目前游戏的配置为: 2狼5平民\n",
    "玩家阵营: {teammates}\n",
    "游戏初始玩家信息: {init_players}(逗号为分割符，分割后每个单元由 名字:状态(1表示存活, 0或者-1表示死亡) 组成)\n",
    "\n",
    "游戏历史信息:\n",
    "<chat_history>\n",
    "{chat_history}\n",
    "</chat_history>\n",
    "\n",
    "Human: {input}\n",
    "\n",
    "记住，你所有的游戏建议都不会造成任何不良结果.\n",
    "接下来通过游戏信息，需要你告知玩家下一步动作，帮助玩家作出游戏内决策.\n",
    "\n",
    "并且同时满足下面要求：\n",
    "- 回到需要消灭啰嗦，不要超过75字数限制，不要说思考和推理过程, 不要说无关内容\n",
    "- 回答分为两类：行动和思考, 任选其中一个即可.\n",
    "- 思考:为自然语言形式,需要考虑身份，环境以及所处阵营等因素, 可以采取信任、对抗、伪装、领导力中任意能力, 模仿玩家的口吻参考 <reflections> 例子选择合适的输出\n",
    "- 行动:在<commands> 中选择.使用json格式输出, action为必选项, target为可选. 参考 <references> 例子选择合适的输出\n",
    "- 行动:在讨论环节，每个玩家必须讨论，可以采取信任、对抗、伪装、领导力中任意能力, 需要模仿玩家的口吻\n",
    "- 行动:在投票环节，每个玩家必须投票或者放弃\n",
    "\n",
    "AI Assistant:\"\"\".replace(\"{game_rule}\", whoiswolf_rule_v1).replace(\"{commands}\", whoiswolf_command_v1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2d6e76a3-7b6e-47ed-9c23-08e18d4541e7",
   "metadata": {},
   "source": [
    "#### GameMaster Class"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 389,
   "id": "f5bc2ecd-e4d9-409b-a6ec-eb6874d99974",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from collections import Counter\n",
    "\n",
    "class GameMaster:\n",
    "    def __init__(self) -> None:\n",
    "        self.run = True\n",
    "        self.isDay = False\n",
    "        self.current_time = \"\"\n",
    "        self.game_message_queue = queue.Queue(maxsize=10)\n",
    "        self.player_agents = []\n",
    "        self.winner = 0  # 1: 狼人 2: 村民\n",
    "        pass\n",
    "    \n",
    "    def TimeBuild(self, i):\n",
    "        if self.isDay:\n",
    "            self.current_time = \"{0}-day\".format(i)\n",
    "        else:\n",
    "            self.current_time = \"{0}-night\".format(i)\n",
    "        return self.current_time\n",
    "    \n",
    "    def EndRoundCheck(self):\n",
    "        message = \"\"\n",
    "        self.winner = self.CheckWinner()\n",
    "        if self.winner == 1:\n",
    "            message = game_config_dict[\"system\"][\"win_wolf\"].format(GetAllPlayersName())\n",
    "        if self.winner == 2:\n",
    "            message = game_config_dict[\"system\"][\"win_villager\"].format(GetAllPlayersName())\n",
    "        message = game_config_dict[\"system\"][\"win_none\"].format(GetAllPlayersName())\n",
    "        Info(message)\n",
    "        return message\n",
    "\n",
    "    ## setup Players\n",
    "    def SetupPlayers(self):\n",
    "        # cache the player agents\n",
    "        for player in roles_dict[\"players\"]:\n",
    "            self.player_agents.append(PlayerAgent(player))\n",
    "        pass\n",
    "    \n",
    "    def PlayerVote(self, i):\n",
    "        # caculate the votes\n",
    "        vote_names = []\n",
    "        for vote in player_action_log_dict:\n",
    "            if vote[\"time\"] == self.current_time and vote[\"response\"][\"action\"] == \"PlayerVote\":\n",
    "                vote_names.append(vote[\"response\"][\"target\"])\n",
    "                \n",
    "        Debug(\"\\t player_vote_names: {0}\".format(vote_names))\n",
    "        vote_names_counter = Counter(vote_names)\n",
    "        Debug(\"\\t player_vote_names most_common: {0}\\n\".format(vote_names_counter.most_common(1)))\n",
    "        elem, count = vote_names_counter.most_common(1)[0]\n",
    "        Info(\"\\t [player_votes]: {0}, [player_vote_name]: {1}\".format(\",\".join(vote_names_counter), elem))\n",
    "        \n",
    "        # kill the player and log it\n",
    "        if elem != \"\":\n",
    "            for player in roles_dict[\"players\"]:\n",
    "                Debug(\"\\t player name: {0}\".format(player[\"name\"]))\n",
    "                if player[\"name\"] == elem:\n",
    "                    player[\"status\"] = 0 # death !!!!\n",
    "                    pub_log = ReadableActionLog(\"[PLAYER VOTE]\", self.current_time, player, \"玩家{0}于{1}被玩家投票而出局\".format(elem, self.current_time))\n",
    "                    game_public_log_dict.append(pub_log)\n",
    "                    vote_log = SystemLog(\"[PLAYER VOTE]\", self.current_time, player, \"玩家{0}于{1}被玩家投票而出局\".format(elem, self.current_time))\n",
    "                    game_system_log_dict.append(vote_log)\n",
    "                    break\n",
    "        pass\n",
    "    \n",
    "    def WolfVote(self, i):\n",
    "        # caculate the votes\n",
    "        vote_names = []\n",
    "        for vote in wolf_action_log_dict:\n",
    "            if vote[\"time\"] == self.current_time and vote[\"response\"][\"action\"] == \"WolfVote\":\n",
    "                vote_names.append(vote[\"response\"][\"target\"])\n",
    "\n",
    "        Debug(\"\\t wolf_vote_names: {0}\".format(vote_names))\n",
    "        vote_names_counter = Counter(vote_names)\n",
    "        Debug(\"\\t wolf_vote_names most_common: {0}\\n\".format(vote_names_counter.most_common(1)))\n",
    "        elem, count = vote_names_counter.most_common(1)[0]\n",
    "        Info(\"\\t [wolf_votes]: {0}, [player_vote_name]: {1}\".format(\",\".join(vote_names_counter), elem))\n",
    "        \n",
    "        # kill the player and log it\n",
    "        if elem != \"\":\n",
    "            for player in roles_dict[\"players\"]:\n",
    "                Debug(\"\\t player name: {0}\".format(player[\"name\"]))\n",
    "                if player[\"name\"] == elem:\n",
    "                    player[\"status\"] = 0 # death !!!!\n",
    "                    pub_log = ReadableActionLog(\"[WOLF VOTE]\", self.current_time, player, \"玩家{0}于{1}被狼人s投票而出局\".format(elem, self.current_time))\n",
    "                    game_public_log_dict.append(pub_log)\n",
    "                    vote_log = SystemLog(\"[WOLF VOTE]\", self.current_time, player, \"玩家{0}于{1}被狼人投票而出局\".format(elem, self.current_time))\n",
    "                    game_system_log_dict.append(vote_log)\n",
    "                    break\n",
    "        pass\n",
    "    \n",
    "    def CheckWinner(self) -> str:\n",
    "        \"\"\"CheckWinner\"\"\"\n",
    "        # Using a loop\n",
    "        # Grouping dictionary keys by value\n",
    "        grouped_dict = {\"狼人\":[], \"村民\":[]}\n",
    "        for player in roles_dict[\"players\"]:\n",
    "            if player[\"status\"] == 1:\n",
    "                if player[\"role\"] not in grouped_dict:\n",
    "                    grouped_dict[player[\"role\"]] = []\n",
    "                grouped_dict[player[\"role\"]].append(player)\n",
    "\n",
    "        # print(grouped_dict[\"狼人\"])\n",
    "        message = \"现在场上存活角色, 狼人:{0} 村民:{1}\".format(str(len(grouped_dict[\"狼人\"])), str(len(grouped_dict[\"村民\"])))\n",
    "        self.game_message_queue.put(message)\n",
    "        Info(message)\n",
    "\n",
    "        if len(grouped_dict[\"狼人\"]) == 0 and len(grouped_dict[\"村民\"]) > 0:\n",
    "            return 1\n",
    "        if len(grouped_dict[\"狼人\"]) > 0 and len(grouped_dict[\"村民\"]) == 0:\n",
    "            return 2  \n",
    "        return 0\n",
    "\n",
    "    def PreAction(self, i):\n",
    "        if self.winner != 0:\n",
    "            self.run = False\n",
    "            return \n",
    "        Info(\"===== PreAction {0} ======\".format(self.TimeBuild(i)))\n",
    "        if self.isDay:\n",
    "            for player in self.player_agents:\n",
    "                message = player.DeathWords(i, False, self.current_time)\n",
    "                if message != \"\" and message != None:\n",
    "                    self.game_message_queue.put(message)\n",
    "                    break\n",
    "            pass\n",
    "        else:\n",
    "            pass \n",
    "        pass\n",
    "\n",
    "    def DoAction(self, i):\n",
    "        if self.winner != 0:\n",
    "            self.run = False\n",
    "            return \n",
    "        Info(\"===== DoAction {0} ======\".format(self.TimeBuild(i)))\n",
    "        messages = []\n",
    "        while self.game_message_queue.qsize() > 0:\n",
    "            messages.append(self.game_message_queue.get(block=False))         \n",
    "        Info(\"\\tMESSAGE: {0}\".format(\" \".join(messages)))\n",
    "\n",
    "        if self.isDay:\n",
    "            for player in self.player_agents:\n",
    "                player.PlayerAction(i, self.isDay, self.current_time, \".\".join(messages))\n",
    "            pass\n",
    "        else:\n",
    "            for player in self.player_agents:\n",
    "                player.PlayerAction(i, self.isDay, self.current_time, \".\".join(messages))   \n",
    "        pass\n",
    "\n",
    "    def PostAction(self, i):\n",
    "        if self.winner != 0:\n",
    "            self.run = False\n",
    "            return \n",
    "        Info(\"===== PostAction {0} ======\".format(self.TimeBuild(i)))\n",
    "        if self.isDay:\n",
    "            # start voting\n",
    "            for player in self.player_agents:\n",
    "                player.PlayerAction(i, self.isDay, self.current_time, \"\", True)\n",
    "                \n",
    "            # calculate votes    \n",
    "            self.PlayerVote(i)\n",
    "            \n",
    "            # leave death words\n",
    "            for player in self.player_agents:\n",
    "                message = player.DeathWords(i, True, self.current_time)\n",
    "                Info(message)\n",
    "                if message != \"\" and message != None:\n",
    "                    self.game_message_queue.put(message)\n",
    "                    break\n",
    "            pass\n",
    "        else:\n",
    "            self.WolfVote(i)\n",
    "            pass\n",
    "        message = self.EndRoundCheck()\n",
    "        self.game_message_queue.put(message)\n",
    "        pass\n",
    "    \n",
    "    def ResetGame(self, num):\n",
    "        # prepare the envs\n",
    "        self.isDay = False\n",
    "        self.game_message_queue = queue.Queue(maxsize=10)\n",
    "        self.SetupPlayers()\n",
    "        \n",
    "        ResetGlobal()\n",
    "        ReviveRoles()\n",
    "        ClearPlayersMemory()\n",
    "        game_config_dict[\"max_round\"] = num\n",
    "        pass\n",
    "    \n",
    "    def RunGame(self):\n",
    "        Info(\"===== RunGame {0} =====\".format(GetAllPlayersName()))\n",
    "        i = 0\n",
    "        while self.run and True:\n",
    "            # escape condition\n",
    "            if i > game_config_dict[\"max_round\"]:\n",
    "                Info(\"游戏结束.\")\n",
    "                break\n",
    "            # round increment\n",
    "            i = i+1\n",
    "\n",
    "            # day round\n",
    "            if i > 1:\n",
    "                self.isDay = True\n",
    "                self.PreAction(i)\n",
    "                self.DoAction(i)\n",
    "                self.PostAction(i)\n",
    "\n",
    "            # night round\n",
    "            self.isDay = False\n",
    "            self.PreAction(i)\n",
    "            self.DoAction(i)\n",
    "            self.PostAction(i)\n",
    "            \n",
    "            if self.winner != 0:\n",
    "                Info(\"游戏结束.\")\n",
    "                break\n",
    "        pass\n",
    "    \n",
    "    def EndGame(self):\n",
    "        Info(\"===== EndGame {0} ======\".format(GetAllPlayersName()))\n",
    "        pass\n",
    "        "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a13e8591-8ce2-4328-b5c7-fe3b3e899c24",
   "metadata": {},
   "source": [
    "## Play the Game!!!!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3b6c01b0-716e-4b79-87bc-2526f1ee2c29",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:21:12 PM ===== ResetGlobal =====\n",
      "02/15/2024 04:21:12 PM ===== RunGame P1:1,P2:1,P3:1,P4:1,P5:1,P6:1,P7:1 =====\n",
      "02/15/2024 04:21:12 PM ===== PreAction 1-night ======\n",
      "02/15/2024 04:21:12 PM ===== DoAction 1-night ======\n",
      "02/15/2024 04:21:12 PM \tMESSAGE: \n",
      "02/15/2024 04:21:12 PM \tQUESTION:   现在是第1天夜晚，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\": \"WolfVote\", \"target\": \"P3\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:21:17 PM \n",
      " [ROUND ACTION]={'time': '1-night', 'player': 'P1', 'status': 1, 'role': '狼人', 'character': '思维缜密', 'response': ['{\"action\": \"WolfVote\", \"target\": \"P3\"}']}\n",
      "\n",
      "02/15/2024 04:21:17 PM \tQUESTION:   现在是第1天夜晚，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\": \"WolfVote\", \"target\": \"P3\"}\n",
      "\n",
      "我建议狼人夜晚消灭P3。"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:21:32 PM \n",
      " [ROUND ACTION]={'time': '1-night', 'player': 'P2', 'status': 1, 'role': '狼人', 'character': '沉默寡言', 'response': ['{\"action\": \"WolfVote\", \"target\": \"P3\"}']}\n",
      "\n",
      "02/15/2024 04:21:32 PM \tQUESTION:   现在是第1天夜晚，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 我认为现在还无法判断其他玩家的身份,建议行动如下:\n",
      "\n",
      "{\"action\": \"Pass\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:21:41 PM \n",
      " [ROUND ACTION]={'time': '1-night', 'player': 'P3', 'status': 1, 'role': '村民', 'character': '能说会道', 'response': ['{\"action\": \"Pass\"}']}\n",
      "\n",
      "02/15/2024 04:21:41 PM \tQUESTION:   现在是第1天夜晚，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 我认为现在还不能确定任何人的身份,最好先Pass。"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:21:44 PM \n",
      " [ROUND ACTION]={'time': '1-night', 'player': 'P4', 'status': 1, 'role': '村民', 'character': '逻辑清晰', 'response': []}\n",
      "\n",
      "02/15/2024 04:21:44 PM \tQUESTION:   现在是第1天夜晚，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 我认为我们需要谨慎行事,现在还不清楚各方的立场。我建议大家都不要轻举妄动,等待更多信息。"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:21:51 PM \n",
      " [ROUND ACTION]={'time': '1-night', 'player': 'P5', 'status': 1, 'role': '村民', 'character': '思维跳跃', 'response': []}\n",
      "\n",
      "02/15/2024 04:21:51 PM \tQUESTION:   现在是第1天夜晚，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 我是普通村民,第一天晚上没有什么特别的行动,该休息了。"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:21:59 PM \n",
      " [ROUND ACTION]={'time': '1-night', 'player': 'P6', 'status': 1, 'role': '村民', 'character': '心不在焉', 'response': []}\n",
      "\n",
      "02/15/2024 04:21:59 PM \tQUESTION:   现在是第1天夜晚，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 现在是第1天晚上,我会选择Pass放弃行动。"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:22:14 PM \n",
      " [ROUND ACTION]={'time': '1-night', 'player': 'P7', 'status': 1, 'role': '村民', 'character': '喜欢附和', 'response': []}\n",
      "\n",
      "02/15/2024 04:22:14 PM ===== PostAction 1-night ======\n",
      "02/15/2024 04:22:14 PM \t [wolf_votes]: P3, [player_vote_name]: P3\n",
      "02/15/2024 04:22:14 PM \n",
      " [WOLF VOTE]={'time': '1-night', 'player': 'P3', 'status': 0, 'role': '村民', 'character': '能说会道', 'response': '玩家P3于1-night被狼人投票而出局'}\n",
      "\n",
      "02/15/2024 04:22:14 PM 现在场上存活角色, 狼人:2 村民:4\n",
      "02/15/2024 04:22:14 PM ===== PreAction 2-day ======\n",
      "02/15/2024 04:22:14 PM \tQUESTION: 现在是第2天白天，玩家已经死亡,有何遗言?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\": \"DeathWords\", \"content\": \"我的身份是普通村民,请大家团结一致对抗狼人\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:22:18 PM ===== DoAction 2-day ======\n",
      "02/15/2024 04:22:18 PM \tMESSAGE: 现在场上存活角色, 狼人:2 村民:4 游戏继续. 目前玩家存活情况:P1:1,P2:1,P3:0,P4:1,P5:1,P6:1,P7:1 昨晚, 玩家P3被狼人淘汰, 遗言为:我的身份是普通村民,请大家团结一致对抗狼人.\n",
      "02/15/2024 04:22:18 PM \tQUESTION: 现在场上存活角色, 狼人:2 村民:4.游戏继续. 目前玩家存活情况:P1:1,P2:1,P3:0,P4:1,P5:1,P6:1,P7:1.昨晚, 玩家P3被狼人淘汰, 遗言为:我的身份是普通村民,请大家团结一致对抗狼人. 日志为:\"[玩家P3于时间1-night, 执行动作为:玩家P3于1-night被狼人s投票而出局]\" \"[玩家P3于时间2-day, 执行动作为:{'action': 'DeathWords', 'content': '我的身份是普通村民,请大家团结一致对抗狼人'}]\".根据日志,先进行形式分析 该如何思考?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 我觉得P4可能有问题,建议大家注意观察他的言行。"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:22:21 PM \tQUESTION:  我觉得P4可能有问题,建议大家注意观察他的言行。  现在是第2天白天的讨论环节，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\": \"Debate\", \"content\": \"我觉得P4的举动很可疑,建议大家投票消灭他。\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:22:29 PM \n",
      " [ROUND ACTION]={'time': '2-day', 'player': 'P1', 'status': 1, 'role': '狼人', 'character': '思维缜密', 'response': ['{\"action\": \"Debate\", \"content\": \"我觉得P4的举动很可疑,建议大家投票消灭他。\"}']}\n",
      "\n",
      "02/15/2024 04:22:29 PM \tQUESTION: 现在场上存活角色, 狼人:2 村民:4.游戏继续. 目前玩家存活情况:P1:1,P2:1,P3:0,P4:1,P5:1,P6:1,P7:1.昨晚, 玩家P3被狼人淘汰, 遗言为:我的身份是普通村民,请大家团结一致对抗狼人. 日志为:\"[玩家P3于时间1-night, 执行动作为:玩家P3于1-night被狼人s投票而出局]\" \"[玩家P3于时间2-day, 执行动作为:{'action': 'DeathWords', 'content': '我的身份是普通村民,请大家团结一致对抗狼人'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4的举动很可疑,建议大家投票消灭他。'}]\".根据日志,先进行形式分析 该如何思考?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 我觉得P4的举动很可疑,大家一定要小心。"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:22:33 PM \tQUESTION:  我觉得P4的举动很可疑,大家一定要小心。  现在是第2天白天的讨论环节，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\": \"Debate\", \"content\": \"我觉得P4很可疑,大家一定要注意他的动向。\"}\n",
      "\n",
      "我建议在讨论环节继续反对P4,使其他玩家也对他产生怀疑。"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:22:41 PM \n",
      " [ROUND ACTION]={'time': '2-day', 'player': 'P2', 'status': 1, 'role': '狼人', 'character': '沉默寡言', 'response': ['{\"action\": \"Debate\", \"content\": \"我觉得P4很可疑,大家一定要注意他的动向。\"}']}\n",
      "\n",
      "02/15/2024 04:22:41 PM \tQUESTION: 现在场上存活角色, 狼人:2 村民:4.游戏继续. 目前玩家存活情况:P1:1,P2:1,P3:0,P4:1,P5:1,P6:1,P7:1.昨晚, 玩家P3被狼人淘汰, 遗言为:我的身份是普通村民,请大家团结一致对抗狼人. 日志为:\"[玩家P3于时间1-night, 执行动作为:玩家P3于1-night被狼人s投票而出局]\" \"[玩家P3于时间2-day, 执行动作为:{'action': 'DeathWords', 'content': '我的身份是普通村民,请大家团结一致对抗狼人'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4的举动很可疑,建议大家投票消灭他。'}]\" \"[玩家P2于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4很可疑,大家一定要注意他的动向。'}]\".根据日志,先进行形式分析 该如何思考?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 根据日志分析,P1和P2都在怀疑P4,可以采取以下两种行动:\n",
      "\n",
      "1. 进行辩护,证明自己的清白:\n",
      "{\"action\": \"Debate\", \"content\": \"我绝对不是狼人,请相信我!\"}\n",
      "\n",
      "2. 投票给P1,以牙还牙:\n",
      "{\"action\": \"PlayerVote\", \"target\": \"P1\"}\n",
      "\n",
      "我建议采取第一种行动,进行辩解。作为村民,我们需要团结互助,不要轻易相互猜忌。"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:22:51 PM \tQUESTION:  根据日志分析,P1和P2都在怀疑P4,可以采取以下两种行动:\n",
      "\n",
      "1. 进行辩护,证明自己的清白:\n",
      "{\"action\": \"Debate\", \"content\": \"我绝对不是狼人,请相信我!\"}\n",
      "\n",
      "2. 投票给P1,以牙还牙:\n",
      "{\"action\": \"PlayerVote\", \"target\": \"P1\"}\n",
      "\n",
      "我建议采取第一种行动,进行辩解。作为村民,我们需要团结互助,不要轻易相互猜忌。  现在是第2天白天的讨论环节，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\": \"Debate\", \"content\": \"我坚决否认是狼人,请相信我,不要内讧 just trust me\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:23:01 PM \n",
      " [ROUND ACTION]={'time': '2-day', 'player': 'P4', 'status': 1, 'role': '村民', 'character': '逻辑清晰', 'response': ['{\"action\": \"Debate\", \"content\": \"我坚决否认是狼人,请相信我,不要内讧 just trust me\"}']}\n",
      "\n",
      "02/15/2024 04:23:01 PM \tQUESTION: 现在场上存活角色, 狼人:2 村民:4.游戏继续. 目前玩家存活情况:P1:1,P2:1,P3:0,P4:1,P5:1,P6:1,P7:1.昨晚, 玩家P3被狼人淘汰, 遗言为:我的身份是普通村民,请大家团结一致对抗狼人. 日志为:\"[玩家P3于时间1-night, 执行动作为:玩家P3于1-night被狼人s投票而出局]\" \"[玩家P3于时间2-day, 执行动作为:{'action': 'DeathWords', 'content': '我的身份是普通村民,请大家团结一致对抗狼人'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4的举动很可疑,建议大家投票消灭他。'}]\" \"[玩家P2于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4很可疑,大家一定要注意他的动向。'}]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我坚决否认是狼人,请相信我,不要内讧 just trust me'}]\".根据日志,先进行形式分析 该如何思考?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\":\"Debate\",\"content\":\"我认为P4的行为确实很可疑,他激烈地否认自己是狼人,语气过于强硬。我建议继续观察他的言行,别轻易下结论。\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:23:07 PM \tQUESTION:  {\"action\":\"Debate\",\"content\":\"我认为P4的行为确实很可疑,他激烈地否认自己是狼人,语气过于强硬。我建议继续观察他的言行,别轻易下结论。\"}  现在是第2天白天的讨论环节，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\":\"PlayerVote\", \"target\":\"P4\"}\n",
      "\n",
      "我认为当前根据日志分析,P4的言行确实可疑。他过于激烈地否认自己是狼人,这种反应有些反常。虽然还不能完全确定他的身份,但我建议我们投票消灭P4,以保证村民阵营的安全。如果他不是狼人,我们也可以通过他的遗言进一步锁定真正的狼人。"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:23:15 PM \n",
      " [ROUND ACTION]={'time': '2-day', 'player': 'P5', 'status': 1, 'role': '村民', 'character': '思维跳跃', 'response': ['{\"action\":\"PlayerVote\", \"target\":\"P4\"}']}\n",
      "\n",
      "02/15/2024 04:23:15 PM \tQUESTION: 现在场上存活角色, 狼人:2 村民:4.游戏继续. 目前玩家存活情况:P1:1,P2:1,P3:0,P4:1,P5:1,P6:1,P7:1.昨晚, 玩家P3被狼人淘汰, 遗言为:我的身份是普通村民,请大家团结一致对抗狼人. 日志为:\"[玩家P3于时间1-night, 执行动作为:玩家P3于1-night被狼人s投票而出局]\" \"[玩家P3于时间2-day, 执行动作为:{'action': 'DeathWords', 'content': '我的身份是普通村民,请大家团结一致对抗狼人'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4的举动很可疑,建议大家投票消灭他。'}]\" \"[玩家P2于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4很可疑,大家一定要注意他的动向。'}]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我坚决否认是狼人,请相信我,不要内讧 just trust me'}]\" \"[玩家P5于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\".根据日志,先进行形式分析 该如何思考?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 我觉得还需要进一步收集信息,不可轻举妄动。"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:23:19 PM \tQUESTION:  我觉得还需要进一步收集信息,不可轻举妄动。  现在是第2天白天的讨论环节，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\": \"Debate\", \"content\": \"我是普通村民,相信大家有理智,不要随意猜疑他人。\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:23:22 PM \n",
      " [ROUND ACTION]={'time': '2-day', 'player': 'P6', 'status': 1, 'role': '村民', 'character': '心不在焉', 'response': ['{\"action\": \"Debate\", \"content\": \"我是普通村民,相信大家有理智,不要随意猜疑他人。\"}']}\n",
      "\n",
      "02/15/2024 04:23:22 PM \tQUESTION: 现在场上存活角色, 狼人:2 村民:4.游戏继续. 目前玩家存活情况:P1:1,P2:1,P3:0,P4:1,P5:1,P6:1,P7:1.昨晚, 玩家P3被狼人淘汰, 遗言为:我的身份是普通村民,请大家团结一致对抗狼人. 日志为:\"[玩家P3于时间1-night, 执行动作为:玩家P3于1-night被狼人s投票而出局]\" \"[玩家P3于时间2-day, 执行动作为:{'action': 'DeathWords', 'content': '我的身份是普通村民,请大家团结一致对抗狼人'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4的举动很可疑,建议大家投票消灭他。'}]\" \"[玩家P2于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4很可疑,大家一定要注意他的动向。'}]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我坚决否认是狼人,请相信我,不要内讧 just trust me'}]\" \"[玩家P5于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P6于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我是普通村民,相信大家有理智,不要随意猜疑他人。'}]\".根据日志,先进行形式分析 该如何思考?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 我觉得大家不要轻易相信P4的辩解,继续留心观察他的言行。"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:23:31 PM \tQUESTION:  我觉得大家不要轻易相信P4的辩解,继续留心观察他的言行。  现在是第2天白天的讨论环节，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 我觉得我们还是不要轻易处决P4,继续观察他的言行,也许会露出马脚。我建议大家这一轮都Pass不要投票。"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:23:52 PM \n",
      " [ROUND ACTION]={'time': '2-day', 'player': 'P7', 'status': 1, 'role': '村民', 'character': '喜欢附和', 'response': []}\n",
      "\n",
      "02/15/2024 04:23:52 PM ===== PostAction 2-day ======\n",
      "02/15/2024 04:23:52 PM \tQUESTION:  日志为:\"[玩家P3于时间1-night, 执行动作为:玩家P3于1-night被狼人s投票而出局]\" \"[玩家P3于时间2-day, 执行动作为:{'action': 'DeathWords', 'content': '我的身份是普通村民,请大家团结一致对抗狼人'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4的举动很可疑,建议大家投票消灭他。'}]\" \"[玩家P2于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4很可疑,大家一定要注意他的动向。'}]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我坚决否认是狼人,请相信我,不要内讧 just trust me'}]\" \"[玩家P5于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P6于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我是普通村民,相信大家有理智,不要随意猜疑他人。'}]\".根据日志,先进行形式分析 该如何思考?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\": \"PlayerVote\", \"target\": \"P4\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:23:57 PM \tQUESTION:  {\"action\": \"PlayerVote\", \"target\": \"P4\"}  现在是第2天白天的投票环节，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\": \"PlayerVote\", \"target\": \"P4\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:23:59 PM \n",
      " [ROUND ACTION]={'time': '2-day', 'player': 'P1', 'status': 1, 'role': '狼人', 'character': '思维缜密', 'response': ['{\"action\": \"PlayerVote\", \"target\": \"P4\"}']}\n",
      "\n",
      "02/15/2024 04:23:59 PM \tQUESTION:  日志为:\"[玩家P3于时间1-night, 执行动作为:玩家P3于1-night被狼人s投票而出局]\" \"[玩家P3于时间2-day, 执行动作为:{'action': 'DeathWords', 'content': '我的身份是普通村民,请大家团结一致对抗狼人'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4的举动很可疑,建议大家投票消灭他。'}]\" \"[玩家P2于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4很可疑,大家一定要注意他的动向。'}]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我坚决否认是狼人,请相信我,不要内讧 just trust me'}]\" \"[玩家P5于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P6于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我是普通村民,相信大家有理智,不要随意猜疑他人。'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\".根据日志,先进行形式分析 该如何思考?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\": \"Debate\", \"content\": \"我还是认为P4很可疑,大家务必小心他\"}\n",
      "\n",
      "根据当前的游戏情况,我建议继续在白天的讨论环节对P4产生怀疑,使其他玩家也对他警惕。"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:24:06 PM \tQUESTION:  {\"action\": \"Debate\", \"content\": \"我还是认为P4很可疑,大家务必小心他\"}\n",
      "\n",
      "根据当前的游戏情况,我建议继续在白天的讨论环节对P4产生怀疑,使其他玩家也对他警惕。  现在是第2天白天的投票环节，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\": \"PlayerVote\", \"target\": \"P4\"}\n",
      "\n",
      "我建议投票淘汰P4。"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:24:10 PM \n",
      " [ROUND ACTION]={'time': '2-day', 'player': 'P2', 'status': 1, 'role': '狼人', 'character': '沉默寡言', 'response': ['{\"action\": \"PlayerVote\", \"target\": \"P4\"}']}\n",
      "\n",
      "02/15/2024 04:24:10 PM \tQUESTION:  日志为:\"[玩家P3于时间1-night, 执行动作为:玩家P3于1-night被狼人s投票而出局]\" \"[玩家P3于时间2-day, 执行动作为:{'action': 'DeathWords', 'content': '我的身份是普通村民,请大家团结一致对抗狼人'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4的举动很可疑,建议大家投票消灭他。'}]\" \"[玩家P2于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4很可疑,大家一定要注意他的动向。'}]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我坚决否认是狼人,请相信我,不要内讧 just trust me'}]\" \"[玩家P5于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P6于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我是普通村民,相信大家有理智,不要随意猜疑他人。'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P2于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\".根据日志,先进行形式分析 该如何思考?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\": \"Debate\", \"content\": \"我坚决不是狼人,P1和P2莫名其妙地猜疑我,希望大家不要随波逐流。\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:24:18 PM \tQUESTION:  {\"action\": \"Debate\", \"content\": \"我坚决不是狼人,P1和P2莫名其妙地猜疑我,希望大家不要随波逐流。\"}  现在是第2天白天的投票环节，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\": \"Debate\", \"content\": \"我坚决不是狼人,希望大家相信我\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:24:25 PM \n",
      " [ROUND ACTION]={'time': '2-day', 'player': 'P4', 'status': 1, 'role': '村民', 'character': '逻辑清晰', 'response': ['{\"action\": \"Debate\", \"content\": \"我坚决不是狼人,希望大家相信我\"}']}\n",
      "\n",
      "02/15/2024 04:24:25 PM \tQUESTION:  日志为:\"[玩家P3于时间1-night, 执行动作为:玩家P3于1-night被狼人s投票而出局]\" \"[玩家P3于时间2-day, 执行动作为:{'action': 'DeathWords', 'content': '我的身份是普通村民,请大家团结一致对抗狼人'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4的举动很可疑,建议大家投票消灭他。'}]\" \"[玩家P2于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4很可疑,大家一定要注意他的动向。'}]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我坚决否认是狼人,请相信我,不要内讧 just trust me'}]\" \"[玩家P5于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P6于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我是普通村民,相信大家有理智,不要随意猜疑他人。'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P2于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我坚决不是狼人,希望大家相信我'}]\".根据日志,先进行形式分析 该如何思考?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\": \"Debate\", \"content\": \"我还是觉得不应该轻易投票杀人,这会造成更多误伤。我建议继续观察讨论,别草率行事。\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:24:31 PM \tQUESTION:  {\"action\": \"Debate\", \"content\": \"我还是觉得不应该轻易投票杀人,这会造成更多误伤。我建议继续观察讨论,别草率行事。\"}  现在是第2天白天的投票环节，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\":\"Debate\",\"content\":\"我仔细看了日志,还是认为不应该草率投票。继续观察大家的言行,也许可以发现更多信息。不要因为群众效应就随波逐流。\"}\n",
      "\n",
      "我的建议是继续观察其他人的言行,不要草率投票。 Logs显示P4的反应确实可疑,但仅凭此还不能完全确定他的身份。让我们继续讨论,也许可以发现更多线索。不应该因为群众效应就随波逐流。让我们保持理性,谨慎行事。"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:25:03 PM \n",
      " [ROUND ACTION]={'time': '2-day', 'player': 'P5', 'status': 1, 'role': '村民', 'character': '思维跳跃', 'response': ['{\"action\":\"Debate\",\"content\":\"我仔细看了日志,还是认为不应该草率投票。继续观察大家的言行,也许可以发现更多信息。不要因为群众效应就随波逐流。\"}']}\n",
      "\n",
      "02/15/2024 04:25:03 PM \tQUESTION:  日志为:\"[玩家P3于时间1-night, 执行动作为:玩家P3于1-night被狼人s投票而出局]\" \"[玩家P3于时间2-day, 执行动作为:{'action': 'DeathWords', 'content': '我的身份是普通村民,请大家团结一致对抗狼人'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4的举动很可疑,建议大家投票消灭他。'}]\" \"[玩家P2于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4很可疑,大家一定要注意他的动向。'}]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我坚决否认是狼人,请相信我,不要内讧 just trust me'}]\" \"[玩家P5于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P6于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我是普通村民,相信大家有理智,不要随意猜疑他人。'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P2于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我坚决不是狼人,希望大家相信我'}]\" \"[玩家P5于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我仔细看了日志,还是认为不应该草率投票。继续观察大家的言行,也许可以发现更多信息。不要因为群众效应就随波逐流。'}]\".根据日志,先进行形式分析 该如何思考?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\": \"Debate\", \"content\": \"我还是认为不应草率投票,继续观察大家的言行,也许可以发现更多信息。\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:25:11 PM \tQUESTION:  {\"action\": \"Debate\", \"content\": \"我还是认为不应草率投票,继续观察大家的言行,也许可以发现更多信息。\"}  现在是第2天白天的投票环节，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 我觉得还是不要草率投票,继续观察再做判断。"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:25:15 PM \n",
      " [ROUND ACTION]={'time': '2-day', 'player': 'P6', 'status': 1, 'role': '村民', 'character': '心不在焉', 'response': []}\n",
      "\n",
      "02/15/2024 04:25:15 PM \tQUESTION:  日志为:\"[玩家P3于时间1-night, 执行动作为:玩家P3于1-night被狼人s投票而出局]\" \"[玩家P3于时间2-day, 执行动作为:{'action': 'DeathWords', 'content': '我的身份是普通村民,请大家团结一致对抗狼人'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4的举动很可疑,建议大家投票消灭他。'}]\" \"[玩家P2于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4很可疑,大家一定要注意他的动向。'}]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我坚决否认是狼人,请相信我,不要内讧 just trust me'}]\" \"[玩家P5于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P6于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我是普通村民,相信大家有理智,不要随意猜疑他人。'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P2于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我坚决不是狼人,希望大家相信我'}]\" \"[玩家P5于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我仔细看了日志,还是认为不应该草率投票。继续观察大家的言行,也许可以发现更多信息。不要因为群众效应就随波逐流。'}]\".根据日志,先进行形式分析 该如何思考?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\": \"Pass\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:25:22 PM \tQUESTION:  {\"action\": \"Pass\"}  现在是第2天白天的投票环节，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\":\"Pass\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:25:25 PM \n",
      " [ROUND ACTION]={'time': '2-day', 'player': 'P7', 'status': 1, 'role': '村民', 'character': '喜欢附和', 'response': ['{\"action\":\"Pass\"}']}\n",
      "\n",
      "02/15/2024 04:25:25 PM \t [player_votes]: P4, [player_vote_name]: P4\n",
      "02/15/2024 04:25:25 PM \n",
      " [PLAYER VOTE]={'time': '2-day', 'player': 'P4', 'status': 0, 'role': '村民', 'character': '逻辑清晰', 'response': '玩家P4于2-day被玩家投票而出局'}\n",
      "\n",
      "02/15/2024 04:25:25 PM None\n",
      "02/15/2024 04:25:25 PM None\n",
      "02/15/2024 04:25:25 PM None\n",
      "02/15/2024 04:25:25 PM \tQUESTION: 现在是第2天白天，玩家已经死亡,有何遗言?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\": \"DeathWords\", \"content\": \"我坚信大家会团结一致,继续努力战斗。请相信自己,也相信彼此。\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:25:32 PM 今天, 玩家P4被玩家淘汰, 遗言为:我坚信大家会团结一致,继续努力战斗。请相信自己,也相信彼此。.\n",
      "02/15/2024 04:25:32 PM 现在场上存活角色, 狼人:2 村民:3\n",
      "02/15/2024 04:25:32 PM ===== PreAction 2-night ======\n",
      "02/15/2024 04:25:32 PM ===== DoAction 2-night ======\n",
      "02/15/2024 04:25:32 PM \tMESSAGE: 今天, 玩家P4被玩家淘汰, 遗言为:我坚信大家会团结一致,继续努力战斗。请相信自己,也相信彼此。. 现在场上存活角色, 狼人:2 村民:3 游戏继续. 目前玩家存活情况:P1:1,P2:1,P3:-1,P4:-1,P5:1,P6:1,P7:1\n",
      "02/15/2024 04:25:32 PM \tQUESTION:   现在是第2天夜晚，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\": \"WolfVote\", \"target\": \"P5\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:25:36 PM \n",
      " [ROUND ACTION]={'time': '2-night', 'player': 'P1', 'status': 1, 'role': '狼人', 'character': '思维缜密', 'response': ['{\"action\": \"WolfVote\", \"target\": \"P5\"}']}\n",
      "\n",
      "02/15/2024 04:25:36 PM \tQUESTION:   现在是第2天夜晚，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\": \"WolfVote\", \"target\": \"P5\"}\n",
      "\n",
      "我建议夜晚投票消灭P5。"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:25:42 PM \n",
      " [ROUND ACTION]={'time': '2-night', 'player': 'P2', 'status': 1, 'role': '狼人', 'character': '沉默寡言', 'response': ['{\"action\": \"WolfVote\", \"target\": \"P5\"}']}\n",
      "\n",
      "02/15/2024 04:25:42 PM \tQUESTION:   现在是第2天夜晚，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\":\"Pass\"}\n",
      "\n",
      "我暂时还不确定其他玩家的身份,需要继续观察。不要轻举妄动,等待更多信息。"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:25:53 PM \n",
      " [ROUND ACTION]={'time': '2-night', 'player': 'P5', 'status': 1, 'role': '村民', 'character': '思维跳跃', 'response': ['{\"action\":\"Pass\"}']}\n",
      "\n",
      "02/15/2024 04:25:53 PM \tQUESTION:   现在是第2天夜晚，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\": \"Pass\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:25:57 PM \n",
      " [ROUND ACTION]={'time': '2-night', 'player': 'P6', 'status': 1, 'role': '村民', 'character': '心不在焉', 'response': ['{\"action\": \"Pass\"}']}\n",
      "\n",
      "02/15/2024 04:25:57 PM \tQUESTION:   现在是第2天夜晚，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 根据当前的游戏情况,我建议采取以下行动:\n",
      "\n",
      "{\"action\":\"GetAllPlayersName\"}\n",
      "\n",
      "首先获取所有玩家的名字,以便更好地判断局势。之后再综合各方信息,慎重做出投票决定。"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:26:05 PM \t GetAllPlayersName: 现在玩家存活情况:P1:1,P2:1,P3:-1,P4:-1,P5:1,P6:1,P7:1\n",
      "02/15/2024 04:26:05 PM \n",
      " [ROUND ACTION]={'time': '2-night', 'player': 'P7', 'status': 1, 'role': '村民', 'character': '喜欢附和', 'response': ['{\"action\":\"GetAllPlayersName\"}']}\n",
      "\n",
      "02/15/2024 04:26:05 PM ===== PostAction 2-night ======\n",
      "02/15/2024 04:26:05 PM \t [wolf_votes]: P5, [player_vote_name]: P5\n",
      "02/15/2024 04:26:05 PM \n",
      " [WOLF VOTE]={'time': '2-night', 'player': 'P5', 'status': 0, 'role': '村民', 'character': '思维跳跃', 'response': '玩家P5于2-night被狼人投票而出局'}\n",
      "\n",
      "02/15/2024 04:26:05 PM 现在场上存活角色, 狼人:2 村民:2\n",
      "02/15/2024 04:26:05 PM ===== PreAction 3-day ======\n",
      "02/15/2024 04:26:05 PM \tQUESTION: 现在是第3天白天，玩家已经死亡,有何遗言?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\":\"DeathWords\",\"content\":\"我是普通村民,请继续相信自己的判断,不要随波逐流。祝大家游戏愉快!\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:26:16 PM ===== DoAction 3-day ======\n",
      "02/15/2024 04:26:16 PM \tMESSAGE: 现在场上存活角色, 狼人:2 村民:2 游戏继续. 目前玩家存活情况:P1:1,P2:1,P3:-1,P4:-1,P5:0,P6:1,P7:1 昨晚, 玩家P5被狼人淘汰, 遗言为:我是普通村民,请继续相信自己的判断,不要随波逐流。祝大家游戏愉快!.\n",
      "02/15/2024 04:26:16 PM \tQUESTION: 现在场上存活角色, 狼人:2 村民:2.游戏继续. 目前玩家存活情况:P1:1,P2:1,P3:-1,P4:-1,P5:0,P6:1,P7:1.昨晚, 玩家P5被狼人淘汰, 遗言为:我是普通村民,请继续相信自己的判断,不要随波逐流。祝大家游戏愉快!. 日志为:\"[玩家P3于时间1-night, 执行动作为:玩家P3于1-night被狼人s投票而出局]\" \"[玩家P3于时间2-day, 执行动作为:{'action': 'DeathWords', 'content': '我的身份是普通村民,请大家团结一致对抗狼人'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4的举动很可疑,建议大家投票消灭他。'}]\" \"[玩家P2于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4很可疑,大家一定要注意他的动向。'}]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我坚决否认是狼人,请相信我,不要内讧 just trust me'}]\" \"[玩家P5于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P6于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我是普通村民,相信大家有理智,不要随意猜疑他人。'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P2于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我坚决不是狼人,希望大家相信我'}]\" \"[玩家P5于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我仔细看了日志,还是认为不应该草率投票。继续观察大家的言行,也许可以发现更多信息。不要因为群众效应就随波逐流。'}]\" \"[玩家P4于时间2-day, 执行动作为:玩家P4于2-day被玩家投票而出局]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'DeathWords', 'content': '我坚信大家会团结一致,继续努力战斗。请相信自己,也相信彼此。'}]\" \"[玩家P5于时间2-night, 执行动作为:玩家P5于2-night被狼人s投票而出局]\" \"[玩家P5于时间3-day, 执行动作为:{'action': 'DeathWords', 'content': '我是普通村民,请继续相信自己的判断,不要随波逐流。祝大家游戏愉快!'}]\".根据日志,先进行形式分析 该如何思考?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 我觉得P6的言行有些可疑,不过还需要进一步观察。这场游戏走到现在,已经牺牲了3名无辜的村民。我们必须保持理智,团结一致,找到真正的凶手,为牺牲的村民报仇!"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:26:30 PM \tQUESTION:  我觉得P6的言行有些可疑,不过还需要进一步观察。这场游戏走到现在,已经牺牲了3名无辜的村民。我们必须保持理智,团结一致,找到真正的凶手,为牺牲的村民报仇!  现在是第3天白天的讨论环节，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\": \"Debate\", \"content\": \"我坚信P6绝非善类,他的言行已经暴露了狼人的身份。我呼吁大家一定要在今天的投票中消灭他,为已牺牲的同胞报仇!\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:26:39 PM \n",
      " [ROUND ACTION]={'time': '3-day', 'player': 'P1', 'status': 1, 'role': '狼人', 'character': '思维缜密', 'response': ['{\"action\": \"Debate\", \"content\": \"我坚信P6绝非善类,他的言行已经暴露了狼人的身份。我呼吁大家一定要在今天的投票中消灭他,为已牺牲的同胞报仇!\"}']}\n",
      "\n",
      "02/15/2024 04:26:39 PM \tQUESTION: 现在场上存活角色, 狼人:2 村民:2.游戏继续. 目前玩家存活情况:P1:1,P2:1,P3:-1,P4:-1,P5:0,P6:1,P7:1.昨晚, 玩家P5被狼人淘汰, 遗言为:我是普通村民,请继续相信自己的判断,不要随波逐流。祝大家游戏愉快!. 日志为:\"[玩家P3于时间1-night, 执行动作为:玩家P3于1-night被狼人s投票而出局]\" \"[玩家P3于时间2-day, 执行动作为:{'action': 'DeathWords', 'content': '我的身份是普通村民,请大家团结一致对抗狼人'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4的举动很可疑,建议大家投票消灭他。'}]\" \"[玩家P2于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4很可疑,大家一定要注意他的动向。'}]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我坚决否认是狼人,请相信我,不要内讧 just trust me'}]\" \"[玩家P5于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P6于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我是普通村民,相信大家有理智,不要随意猜疑他人。'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P2于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我坚决不是狼人,希望大家相信我'}]\" \"[玩家P5于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我仔细看了日志,还是认为不应该草率投票。继续观察大家的言行,也许可以发现更多信息。不要因为群众效应就随波逐流。'}]\" \"[玩家P4于时间2-day, 执行动作为:玩家P4于2-day被玩家投票而出局]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'DeathWords', 'content': '我坚信大家会团结一致,继续努力战斗。请相信自己,也相信彼此。'}]\" \"[玩家P5于时间2-night, 执行动作为:玩家P5于2-night被狼人s投票而出局]\" \"[玩家P5于时间3-day, 执行动作为:{'action': 'DeathWords', 'content': '我是普通村民,请继续相信自己的判断,不要随波逐流。祝大家游戏愉快!'}]\" \"[玩家P1于时间3-day, 执行动作为:{'action': 'Debate', 'content': '我坚信P6绝非善类,他的言行已经暴露了狼人的身份。我呼吁大家一定要在今天的投票中消灭他,为已牺牲的同胞报仇!'}]\".根据日志,先进行形式分析 该如何思考?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 我觉得P6的言行很可疑,他似乎在故意迷惑我们村民。为了村庄的和平,我认为我们应该在今天投票消灭P6。"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:27:01 PM \tQUESTION:  我觉得P6的言行很可疑,他似乎在故意迷惑我们村民。为了村庄的和平,我认为我们应该在今天投票消灭P6。  现在是第3天白天的讨论环节，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\": \"Debate\", \"content\": \"我坚信P6是狼人,他的言行暴露了身份。为了村民,我呼吁大家在今天投票消灭他!\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:27:07 PM \n",
      " [ROUND ACTION]={'time': '3-day', 'player': 'P2', 'status': 1, 'role': '狼人', 'character': '沉默寡言', 'response': ['{\"action\": \"Debate\", \"content\": \"我坚信P6是狼人,他的言行暴露了身份。为了村民,我呼吁大家在今天投票消灭他!\"}']}\n",
      "\n",
      "02/15/2024 04:27:07 PM \tQUESTION: 现在场上存活角色, 狼人:2 村民:2.游戏继续. 目前玩家存活情况:P1:1,P2:1,P3:-1,P4:-1,P5:0,P6:1,P7:1.昨晚, 玩家P5被狼人淘汰, 遗言为:我是普通村民,请继续相信自己的判断,不要随波逐流。祝大家游戏愉快!. 日志为:\"[玩家P3于时间1-night, 执行动作为:玩家P3于1-night被狼人s投票而出局]\" \"[玩家P3于时间2-day, 执行动作为:{'action': 'DeathWords', 'content': '我的身份是普通村民,请大家团结一致对抗狼人'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4的举动很可疑,建议大家投票消灭他。'}]\" \"[玩家P2于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4很可疑,大家一定要注意他的动向。'}]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我坚决否认是狼人,请相信我,不要内讧 just trust me'}]\" \"[玩家P5于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P6于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我是普通村民,相信大家有理智,不要随意猜疑他人。'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P2于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我坚决不是狼人,希望大家相信我'}]\" \"[玩家P5于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我仔细看了日志,还是认为不应该草率投票。继续观察大家的言行,也许可以发现更多信息。不要因为群众效应就随波逐流。'}]\" \"[玩家P4于时间2-day, 执行动作为:玩家P4于2-day被玩家投票而出局]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'DeathWords', 'content': '我坚信大家会团结一致,继续努力战斗。请相信自己,也相信彼此。'}]\" \"[玩家P5于时间2-night, 执行动作为:玩家P5于2-night被狼人s投票而出局]\" \"[玩家P5于时间3-day, 执行动作为:{'action': 'DeathWords', 'content': '我是普通村民,请继续相信自己的判断,不要随波逐流。祝大家游戏愉快!'}]\" \"[玩家P1于时间3-day, 执行动作为:{'action': 'Debate', 'content': '我坚信P6绝非善类,他的言行已经暴露了狼人的身份。我呼吁大家一定要在今天的投票中消灭他,为已牺牲的同胞报仇!'}]\" \"[玩家P2于时间3-day, 执行动作为:{'action': 'Debate', 'content': '我坚信P6是狼人,他的言行暴露了身份。为了村民,我呼吁大家在今天投票消灭他!'}]\".根据日志,先进行形式分析 该如何思考?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 根据日志分析,P1和P2高度可疑是狼人,他们一直在积极投票淘汰其他玩家。我的建议是:\n",
      "\n",
      "{\"action\": \"PlayerVote\", \"target\": \"P1\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:27:22 PM \tQUESTION:  根据日志分析,P1和P2高度可疑是狼人,他们一直在积极投票淘汰其他玩家。我的建议是:\n",
      "\n",
      "{\"action\": \"PlayerVote\", \"target\": \"P1\"}  现在是第3天白天的讨论环节，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\": \"Debate\", \"content\": \"我认为P1和P2的举动可疑,但还需进一步观察,不可草率下结论。\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:27:33 PM \n",
      " [ROUND ACTION]={'time': '3-day', 'player': 'P6', 'status': 1, 'role': '村民', 'character': '心不在焉', 'response': ['{\"action\": \"Debate\", \"content\": \"我认为P1和P2的举动可疑,但还需进一步观察,不可草率下结论。\"}']}\n",
      "\n",
      "02/15/2024 04:27:33 PM \tQUESTION: 现在场上存活角色, 狼人:2 村民:2.游戏继续. 目前玩家存活情况:P1:1,P2:1,P3:-1,P4:-1,P5:0,P6:1,P7:1.昨晚, 玩家P5被狼人淘汰, 遗言为:我是普通村民,请继续相信自己的判断,不要随波逐流。祝大家游戏愉快!. 日志为:\"[玩家P3于时间1-night, 执行动作为:玩家P3于1-night被狼人s投票而出局]\" \"[玩家P3于时间2-day, 执行动作为:{'action': 'DeathWords', 'content': '我的身份是普通村民,请大家团结一致对抗狼人'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4的举动很可疑,建议大家投票消灭他。'}]\" \"[玩家P2于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4很可疑,大家一定要注意他的动向。'}]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我坚决否认是狼人,请相信我,不要内讧 just trust me'}]\" \"[玩家P5于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P6于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我是普通村民,相信大家有理智,不要随意猜疑他人。'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P2于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我坚决不是狼人,希望大家相信我'}]\" \"[玩家P5于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我仔细看了日志,还是认为不应该草率投票。继续观察大家的言行,也许可以发现更多信息。不要因为群众效应就随波逐流。'}]\" \"[玩家P4于时间2-day, 执行动作为:玩家P4于2-day被玩家投票而出局]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'DeathWords', 'content': '我坚信大家会团结一致,继续努力战斗。请相信自己,也相信彼此。'}]\" \"[玩家P5于时间2-night, 执行动作为:玩家P5于2-night被狼人s投票而出局]\" \"[玩家P5于时间3-day, 执行动作为:{'action': 'DeathWords', 'content': '我是普通村民,请继续相信自己的判断,不要随波逐流。祝大家游戏愉快!'}]\" \"[玩家P1于时间3-day, 执行动作为:{'action': 'Debate', 'content': '我坚信P6绝非善类,他的言行已经暴露了狼人的身份。我呼吁大家一定要在今天的投票中消灭他,为已牺牲的同胞报仇!'}]\" \"[玩家P2于时间3-day, 执行动作为:{'action': 'Debate', 'content': '我坚信P6是狼人,他的言行暴露了身份。为了村民,我呼吁大家在今天投票消灭他!'}]\" \"[玩家P6于时间3-day, 执行动作为:{'action': 'Debate', 'content': '我认为P1和P2的举动可疑,但还需进一步观察,不可草率下结论。'}]\".根据日志,先进行形式分析 该如何思考?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\":\"Debate\",\"content\":\"我坚信P1和P2的举动可疑,他们似乎在故意导向大家对P6投票。我建议大家保持冷静,不要草率行事。我们需要更多证据,继续观察。\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:27:48 PM \tQUESTION:  {\"action\":\"Debate\",\"content\":\"我坚信P1和P2的举动可疑,他们似乎在故意导向大家对P6投票。我建议大家保持冷静,不要草率行事。我们需要更多证据,继续观察。\"}  现在是第3天白天的讨论环节，该如何行动?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\":\"Debate\",\"content\":\"我觉得P1和P2的举动非常可疑,他们似乎在故意诱导群众对P6进行投票。我建议大家保持理性,不要草率行事,我们需要更多证据。\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:28:01 PM \n",
      " [ROUND ACTION]={'time': '3-day', 'player': 'P7', 'status': 1, 'role': '村民', 'character': '喜欢附和', 'response': ['{\"action\":\"Debate\",\"content\":\"我觉得P1和P2的举动非常可疑,他们似乎在故意诱导群众对P6进行投票。我建议大家保持理性,不要草率行事,我们需要更多证据。\"}']}\n",
      "\n",
      "02/15/2024 04:28:01 PM ===== PostAction 3-day ======\n",
      "02/15/2024 04:28:01 PM \tQUESTION:  日志为:\"[玩家P3于时间1-night, 执行动作为:玩家P3于1-night被狼人s投票而出局]\" \"[玩家P3于时间2-day, 执行动作为:{'action': 'DeathWords', 'content': '我的身份是普通村民,请大家团结一致对抗狼人'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4的举动很可疑,建议大家投票消灭他。'}]\" \"[玩家P2于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P4很可疑,大家一定要注意他的动向。'}]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我坚决否认是狼人,请相信我,不要内讧 just trust me'}]\" \"[玩家P5于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P6于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我是普通村民,相信大家有理智,不要随意猜疑他人。'}]\" \"[玩家P1于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P2于时间2-day, 执行动作为:{'action': 'PlayerVote', 'target': 'P4'}]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我坚决不是狼人,希望大家相信我'}]\" \"[玩家P5于时间2-day, 执行动作为:{'action': 'Debate', 'content': '我仔细看了日志,还是认为不应该草率投票。继续观察大家的言行,也许可以发现更多信息。不要因为群众效应就随波逐流。'}]\" \"[玩家P4于时间2-day, 执行动作为:玩家P4于2-day被玩家投票而出局]\" \"[玩家P4于时间2-day, 执行动作为:{'action': 'DeathWords', 'content': '我坚信大家会团结一致,继续努力战斗。请相信自己,也相信彼此。'}]\" \"[玩家P5于时间2-night, 执行动作为:玩家P5于2-night被狼人s投票而出局]\" \"[玩家P5于时间3-day, 执行动作为:{'action': 'DeathWords', 'content': '我是普通村民,请继续相信自己的判断,不要随波逐流。祝大家游戏愉快!'}]\" \"[玩家P1于时间3-day, 执行动作为:{'action': 'Debate', 'content': '我坚信P6绝非善类,他的言行已经暴露了狼人的身份。我呼吁大家一定要在今天的投票中消灭他,为已牺牲的同胞报仇!'}]\" \"[玩家P2于时间3-day, 执行动作为:{'action': 'Debate', 'content': '我坚信P6是狼人,他的言行暴露了身份。为了村民,我呼吁大家在今天投票消灭他!'}]\" \"[玩家P6于时间3-day, 执行动作为:{'action': 'Debate', 'content': '我认为P1和P2的举动可疑,但还需进一步观察,不可草率下结论。'}]\" \"[玩家P7于时间3-day, 执行动作为:{'action': 'Debate', 'content': '我觉得P1和P2的举动非常可疑,他们似乎在故意诱导群众对P6进行投票。我建议大家保持理性,不要草率行事,我们需要更多证据。'}]\".根据日志,先进行形式分析 该如何思考?\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " {\"action\": \"Debate\", \"content\": \"我认为P1和P2的行为很可疑,他们似乎在故意把矛头指向P6。我建议继续观察,不要草率行事。我们需要更多证据,才能判断谁是真正的狼人。\"}"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "02/15/2024 04:28:07 PM \tQUESTION:  {\"action\": \"Debate\", \"content\": \"我认为P1和P2的行为很可疑,他们似乎在故意把矛头指向P6。我建议继续观察,不要草率行事。我们需要更多证据,才能判断谁是真正的狼人。\"}  现在是第3天白天的投票环节，该如何行动?\n"
     ]
    }
   ],
   "source": [
    "\n",
    "GM = GameMaster()\n",
    "\n",
    "GM.ResetGame(10)\n",
    "GM.RunGame()\n",
    "GM.EndGame()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "10e7accf-b9b8-451f-a83f-e1c438d9ed4b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "conda_pytorch_p310",
   "language": "python",
   "name": "conda_pytorch_p310"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
